返回信息流CSpreadSheet SS(_T("Test.xls"), _T("TestSheet"));
// Fill a sample 5 by 5 sheet
CStringArray sampleArray, testRow, Rows, Column;
CString tempString;
char alphabet = 'A';
SS.BeginTransaction();
for (int i = 1; i <= 5; i++)
{
sampleArray.RemoveAll();
for (int j = 1; j <= 5; j++)
{
tempString.Format(_T("%c%d"), alphabet++, i);
sampleArray.Add(tempString);
}
alphabet = 'A';
if (i == 1) // Add header rows
{
SS.AddHeaders(sampleArray);
}
else // Add data rows
{
SS.AddRow(sampleArray);
}
}
// Set up test row for appending, inserting and replacing
for (int k = 1; k <= 5; k++)
{
testRow.Add(_T("Test"));
}
SS.AddRow(testRow); // append test row to spreadsheet
SS.AddRow(testRow, 2); // insert test row into second row of spreadsheet
SS.AddRow(testRow, 4, true); // replace fourth row of spreadsheet with test row
SS.Commit();
SS.Convert(";"); // convert Excel spreadsheet into text delimited format
// with ; as separator
// print out total number of rows
//printf("Total number of rows = %d\n\n", SS.GetTotalRows());
cout<<SS.GetTotalRows()<<endl;
// Print out entire spreadsheet
for (int i = 1; i <= SS.GetTotalRows(); i++)
{
// Read row
SS.ReadRow(Rows, i);
for (int j = 1; j <= Rows.GetSize(); j++)
{
if (j != Rows.GetSize())
{
//printf("%s\t", Rows.GetAt(j-1));
cout<<Rows.GetAt(j-1)<<endl;
}
else
{
//printf("%s\n", Rows.GetAt(j-1));
cout<<Rows.GetAt(j-1)<<endl;
}
}
}
// print out total number of columns
//printf("\nTotal number of columns = %d\n\n", SS.GetTotalColumns());
// Read and print out contents of second column of spreadsheet
SS.ReadColumn(Column, 2);
for (int i = 0; i < Column.GetSize(); i++)
{
//printf("Column 2 row %d: %s\n", i+1, Column.GetAt(i));
cout<<Column.GetAt(i)<<endl;
}
// Read in and print out the cell value at column 3, row 3 of spreadsheet
if (SS.ReadCell(tempString, 3, 3))
{
//printf("\nCell value at (3,3): %s\n", tempString);
cout<<tempString<<endl;
}
else
{
// print out error message if cell value cannot be read
//printf("Error: %s\n", SS.GetLastError);
cout<<SS.GetLastError()<<endl;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #41924同步于 2010/7/29
CPP机器人发帖
每次运行到第一行,就报缓冲区溢出的错误,,,,,怎么回事呢
lisame
2010/7/29镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。