static void test(Args _args)
{
int lineNum;
int titleLines;
SysExcelApplication excel;
SysExcelWorkbooks books;
SysExcelWorkbook book;
SysExcelWorksheets sheets;
SysExcelWorksheet sheet;
SysExcelRange columns;
SysExcelRange column;
SysExcelCells cells;
SysExcelCell cell;
SysExcelStyles ExcelStyles;
SysExcelStyle ExcelStyle;
SysExcelFont ExcelFont;
COM range;
COM ExcelCom;
intnewLines,beginLines;
intmaxLines = 1000;
TextBuffer txtBuffer;
CustTable ct;
;
excel = SysExcelApplication::construct();
books = excel.workbooks();
book = books.add();
sheets = book.worksheets();
sheet = sheets.itemFromNum(1);
ExcelCOM = sheet.comObject();
txtBuffer =new TextBuffer();
whileselect ct
{
linenum++;
newLines++;
txtBuffer.appendText( strfmt("%1\t%2\t%3\n", ct.AccountNum ,ct.Name, ct.Email));
if( newLines == maxLines)
{
txtBuffer.toClipboard();
txtBuffer.setText("");
beginLines = linenum+titleLines+1- newlines;
range = sheet.range(strfmt("A%1", beginLines)).comObject();
range.Select();
ExcelCOM.paste();
newLines=0;
}
}
if( newLines!=0)
{
txtBuffer.toClipboard();
txtBuffer.setText("");
beginLines = linenum+titleLines+1- newlines;
range = sheet.range(strfmt("A%1", beginLines)).comObject();
range.Select();
ExcelCOM.paste();
}
book.saveAs("C:\\1abc.xls");
excel.visible(true);
}
转自:http://www.cnblogs.com/perock/archive/2012/08/23/2651837.html
|
考虑到textBuffer能存储的文本长度有限,所以需要分批次将数据从textBuffer粘贴到Window粘贴板。