Method 1:
CStdioFile File;
CString str;
File.Open ("D\\1.xls", cfile::modecreate| Cfile::modereadwrite)///If the file does not exist beforehand, it needs to be cfile::modecreate, otherwise it will not need
Keywords: location, processing type, event start time, event end time, processing person, processing time, escalation type, event recording name, event picture name, notes
Str. Format ("%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c", "Location", 9, "Processing Type", 9, "event Start Time", 9, "event End Time", 9, "handler", 9, "Processing Time", 9, "escalation type" ", 9," event recording name ", 9," event picture name ", 9," remark ", 13);
File.writestring (str);
File.close ();
Add a row of data
Str. Format ("%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c", strcamname,9,phandleeventname[sjlx],9,row2,9,row3,9,row7,9, row5,9,streventname,9, str_linkvideopath,9, str_linkpicpath,9,row8,13);
File.writestring (str);
Method 2:
CDatabase database;
CString sSQL;
Ssql.format ("driver={%s};D sn="; Firstrowhasnames=1; Readonly=false; Create_db=\ "%s\";D bq=%s ", Sdriver, Sexcelfile, sexcelfile);
//CREATE DATABASE (i.e. Excel tabular file)
if ( Database. OpenEx (Ssql,cdatabase::noodbcdialog))
{
//CREATE TABLE structure =
sSQL = "CREATE Table Backup Event List (location text, processing type text, event start time text, event end time text, processing person text, processing time text, escalation type text, event video Name text, event picture Name text, notes text)";
database. ExecuteSQL (sSQL);
Ssql.format ("INSERT into Backup Event list (location, processing type, event start time, event end time, processing person, processing time, escalation type, event recording name, event picture name, remarks) VALUES ('%s ' , '%s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%s '),
Strcamname,phandleeventname[sjlx],row2,row3,row7, Row5,streventname, Str_linkvideopath, STR_LINKPICPATH,ROW8);
Database. ExecuteSQL (sSQL);
Close the database
Database. Close ();
}
MFC in C + + creates an Excel table and adds data to an Excel table method