Home > Back-end >  C builder will StringGarid import of different contents of different working table to the same workb
C builder will StringGarid import of different contents of different working table to the same workb

Time:10-04

Void __fastcall CrnExportStringGrid2Excel (TStringGrid * sg, String strXlsFile)
{
The Variant vExcelApp vSheet;
Try
{
VExcelApp=the Variant: : CreateObject (" Excel. Application ");
}
The catch (... )
{
MessageBox (0, TEXT (" start Excel error, may be not installed Excel. "),
The TEXT (" ExportStringGrid2Excel "), MB_OK | MB_ICONERROR);
return;
}

//hide the Excel interface
VExcelApp. OlePropertySet (" Visible ", false);
//create a new worksheet
VExcelApp. OlePropertyGet (" Workbooks "). OleFunction (" Add ", 1);//work table
//operate the working table
VSheet=vExcelApp. OlePropertyGet (" ActiveWorkbook ")
OlePropertyGet (" Sheets ", 1);
//set the Excel document font
VSheet. OleProcedure (" Select ");
VSheet. OlePropertyGet (" Cells "). OleProcedure (" Select ");
VExcelApp. OlePropertyGet (" Selection "). OlePropertyGet (" Font ")
OlePropertySet (" Size ", sg - & gt; The Font - & gt; The Size);
VExcelApp. OlePropertyGet (" Selection "). OlePropertyGet (" Font ")
OlePropertySet (" Name ", WideString (sg - & gt; The Font - & gt; Name));
VExcelApp. OlePropertyGet (" Selection "). OlePropertyGet (" Font ")
OlePropertySet (" FontStyle WideString (" conventional "));
VSheet. OlePropertyGet (" Cells ", 1, 1). OleProcedure (" Select ");
//form the number of rows
Int nRowCount=sg - & gt; RowCount;
NRowCount=nRowCount & lt; 2? 2: nRowCount;
//the column number of the form
Int nColCount=sg - & gt; ColCount;
NColCount=nColCount & lt; 1? 1: nColCount;

For (int I=1; I & lt; NRowCount; I++)
{
//63 63 72 75 6 2 63 6 f e e d
For (int j=1; J & lt; NColCount; J++)
{
VSheet. OlePropertyGet (" Cells ", I, j)
OlePropertySet (" Value ", WideString (sg - & gt; Cells [j] [I]));
}
}

//save the Excel documents and exit the
ActiveWorkbook vExcelApp. OlePropertyGet (" ")
OleFunction (" SaveAs ", WideString (strXlsFile));
VExcelApp. OleFunction (" Quit ");

VSheet=Unassigned;
VExcelApp=Unassigned;

//end
MessageBox (0, TEXT (" conversion over!" ),
The TEXT (" ExportStringGrid2Excel "), MB_OK | MB_ICONINFORMATION);
}
This is the contents of the StringGarid imported into the first worksheet in the workbook, existing a demand, to the different content of StringGarid import to work in the same workbook of different tables, how to modify the code? Pray god to give detailed help, don't only broad, said can cite some instance!

CodePudding user response:

//hide the Excel interface
VExcelApp. OlePropertySet (" Visible ", false);
//create a new worksheet
VExcelApp. OlePropertyGet (" Workbooks "). OleFunction (" Add ", 1);//work table
//operate the working table
VSheet=vExcelApp. OlePropertyGet (" ActiveWorkbook ")
OlePropertyGet (" Sheets ", 1);
According to the demand change this code to go, I estimate is to modify the
VSheet=vExcelApp. OlePropertyGet (" ActiveWorkbook ")
OlePropertyGet (" Sheets ", 1);
You search the function of the correlation function

CodePudding user response:

Don't estimate! I didn't change, modified, where to check the function of the correlation function?
  • Related