Home > Back-end >  You come in for help! How to deposit the stringgrid content to excel!
You come in for help! How to deposit the stringgrid content to excel!

Time:10-09

Masters taught you about, no operations have been carried out to excel! I demand is the stringgrid content directly to the deposit to excel in, do not need to select the file storage path to the file, click save as to save directly to the program directory and file called Edit3 content, and how to set the default file suffix?


 
Void __fastcall TZTE_SN: : Button5Click (TObject * Sender)
{
If (Edit3 - & gt; Text=="")
{
ShowMessage (" please Mr As a path, and then click save ");
return;
}
SaveDialog1 - & gt; DefaultExt=". XLS ";//the default extension
//StrFileName - & gt; SaveToFile (Edit3 - & gt; Text. C_str ());
//SaveDialog1 - & gt; FileName=Edit3 - & gt; The Text. The c_str ();
//AnsiString StrFileName=GetCurrentDir () + AnsiString (Edit3 - & gt; Text. C_str ());

//ShowMessage (" save the complete ");
//-- -- -- -- -- -- -- -- -- -- -- -- - save the data into excel -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/*
//AnsiString StrFileName=ExtractFilePath (" Export. XLS ");
if(! FileExists (StrFileName))
{
MessageBox (Handle, Export Excel file. XLS "does not exist!" , the "message", MB_OK);
return;
}
*/
The Variant ExcelApp;//object
The Variant WorkBook1;//work thin
The Variant WorkSheet1;//work table
The Variant Range;//range
Try
{
ExcelApp=the Variant: : CreateObject (" Excel. Application ");
}
The catch (... )
{
MessageBox (Handle, "unable to start the Excel!" , the "message", MB_ICONSTOP | MB_OK);
return;
}
ExcelApp. OlePropertySet (" Visible ", false);//set the Excel to invisible
//open the specified Excel file, file should set only one Sheet
ExcelApp. OlePropertyGet (" WorkBooks "). OleProcedure (" Open ", StrFileName c_str ());
WorkBook1=ExcelApp. OlePropertyGet (" ActiveWorkBook ");
WorkSheet1=WorkBook1. OlePropertyGet (" ActiveSheet ");//get the current default Sheet
//empty EXCEL table data
Int nRow=WorkSheet1. OlePropertyGet (" UsedRange "). OlePropertyGet (" Rows ".) OlePropertyGet (" Count ");
Int nCol=WorkSheet1. OlePropertyGet (" UsedRange "). OlePropertyGet (" Columns "). OlePropertyGet (" Count ");
For (int I=5; I<=nRow + 1; I++)
WorkSheet1. OlePropertyGet (" Rows ", I). OlePropertySet (" Value ", "");
//to Excel table assignment
for(int j=1; j<10; J++)
{
for(int i=1; I<10; I++)
{
AnsiString StrValue=https://bbs.csdn.net/topics/IntToStr (I * j);
WorkSheet1. OlePropertyGet (" Cells ", I + 4, j). OlePropertySet (" Value ", StrValue c_str ());
}
}
AnsiString StrRange="A" + IntToStr (1) + ":" I + IntToStr (nRow);//the retrieval scope
The Range=WorkSheet1. OlePropertyGet (" Range ", StrRange. C_str ());
WorkBook1. OleProcedure (" Save ", Edit3 - & gt; Text. C_str ());//save the form
WorkBook1. OleProcedure (" Close ");//close form
ExcelApp. OleFunction (" Quit ");//exit Excel

//-- -- -- -- -- -- -- -- -- -- -- -- save completed, emptying the contents -- -- -- -- -- -- -- -- -- -- -- -- --
Edit3 - & gt; The Clear ();
int i;
for(i=1; I<501; I++)
StringGrid1 - & gt; Rows [I] - & gt; The Clear ();
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TZTE_SN: : StringGrid1Click (TObject * Sender)
{
StringGrid1 - & gt; The Options=StringGrid1 - & gt; The Options & lt; }
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TZTE_SN: : Button6Click (TObject * Sender)
{
int i;
for(i=0; I<501; I++)
{
StringGrid1 - & gt; Cells [0] [I + 1)=I + 1;
StringGrid1 - & gt; Cells [1] [I + 1)="aaaaa";
StringGrid1 - & gt; Cells [2] [I + 1)="BBBBB";
//String strCell=StringGrid1 - & gt; Cells [I + 1], [I + 1);
//make StrinGrid editable

}
Edit3 - & gt; Text=FormatDateTime (" YYYY - MM - DD hh - MM - ss ", Now ()) + "___".
//FormatDateTime (" MM - DD YYYY - hh: MM: ss ZZZ ", Now ());
//get the current system date

}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --




Void __fastcall TZTE_SN: : FormCreate (TObject * Sender)
{
StringGrid1 - & gt; ColWidths [0]=55;
StringGrid1 - & gt; ColWidths [1]=110;
StringGrid1 - & gt; ColWidths [2]=110;
StringGrid1 - & gt; RowHeights [0, 0]=25;
StringGrid1 - & gt; Cells [0] [0]="serial number";
StringGrid1 - & gt; Cells [1] [0]="AAAAAAA_SN";
StringGrid1 - & gt; Cells [2] [0]="ZZZZZZZ_SN";
/*
for(int j=0; j<3; J++)
{
For (int I=0; I<500; I++)
{
This - & gt; StringGrid1 - & gt; A + 1 bonus to Cells [j] [I + 1)=IntToStr (I * j);

}
}
*/
int n;
For (n=0; N<500; N++)
{
The column number of the//StringGrid
//StringGrid1 - & gt; ColCount=n + 1;
//StringGrid the number of rows
StringGrid1 - & gt; RowCount=n + 2;
//the case of the width of the column I
//StringGrid1 - & gt; ColWidths [n + 1)=50;
//the ith row height
StringGrid1 - & gt; RowHeights [0, the n + 1)=20.

}

}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

I have no master!

CodePudding user response:

Advstringgrid has the visual control and its adjacent to excel export, but will pop-up dialog to save!

CodePudding user response:

Long ago I was standing on a light red code, data export to Excel file StringGrid, if need be, leave a mailbox, I sent to you,

CodePudding user response:

Demon elder brother is warm-hearted man,
  • Related