Concrete realization
First, including the header file of Excel file operation class
# contains "CSpreadSheet.h"
Secondly, create a new Excel file and write the default data.
//Create a new Excel file name and path, and TestSheet is the name of the internal table.
CSpreadSheet SS("c:\\Test.xls "," test sheet ");
CStringArray sampleArray,testRow
SS. begin transaction();
//Add a title
Sample array. remove all();
Sample array. Add ("name");
Sample array. Add ("age");
SS. add headers(sample array);
//Add data
CString strName[] = {"Xu Jingzhou", "Seo Ji-Hye", "Guo Hui", "Niu Yingjun" and "Zhu Xiaopeng"};
CString strAge[] = {"27 "," 23 "," 28 "," 27 "," 26 " };
for(int I = 0; I< sizeof (strname)/sizeof (cstring); i++)
{
Sample array. remove all();
Sample array. add(strName[I]);
Sample array. add(strAge[I]);
SS. AddRow(sample array);
}
SS. commit();
Third, read the Excel file data.
CSpreadSheet SS("c:\\Test.xls "," test sheet ");
CStringArray row, column.
//Empty the list box
m_AccessList。 reset content();
for(int I = 1; I<= SS. GetTotalRows(); i++)
{
//Read a line
SS. ReadRow(Rows,I);
CString strContents =
for(int j = 1; J<= line. GetSize(); j++)
{
If (j == 1)
strContents = Rows。 GetAt(j- 1);
other
StrContents = strContents+"->+ line. GetAt(j- 1);
}
m_AccessList。 AddString(str contents);
}