Home > Back-end >  Win10 64 under DELPHI XE10 according to excel Sheet split save is not successful
Win10 64 under DELPHI XE10 according to excel Sheet split save is not successful

Time:09-24

Sheet1 have a primitive form, the inside of the extracted data to generate sheet2, intends to sheet2 save as a new XLSX file, tried various methods to search a N replication to post more, the result is a new form there are two sheet, beg god give directions!

Procedure TForm1. Button1Click (Sender: TObject);
Var
Bt: String;
ExcelApp: Variant;
EB1: Variant;
I, j, l, m, MaxRow: Integer;
The begin
Bt:=ComboBox1. Text;
L:=ComboBox1. ItemIndex;
If messagebox (handle, Pchar (' confirmed a total of + IntToStr (ComboBox2. Items. Count) a [' + '
+ bt + '] split? '), 'prompt', MB_YESNO)=IDYES then
The begin
ExcelApp:=CreateOleObject (' Excel. Application);
EB1:=ExcelApp. WorkBooks. Open (Edit1. Text);
ExcelApp. ActiveWorkBook. Sheets. The Add
(After:=ExcelApp. ActiveWorkBook. Sheets [1]).
MaxRow:=EB1. Sheets. [1] UsedRange. Rows. Count;

The for m:=0 to ComboBox2. Items. Do the Count - 1
The begin
EB1. Sheets [2]. Delete;
ExcelApp. ActiveWorkBook. Sheets. The Add
(After:=ExcelApp. ActiveWorkBook. Sheets [1]).
ComboBox2. ItemIndex:=m;
EB1. Sheets [1]. The Rows [1]. The Copy;
EB1. Sheets [2]. The Rows [1]. The PasteSpecial;
J:=2;
For I:=1 to MaxRow do
The begin
If EB1. Sheets [1]. The Cells [I, m + 1] Text=ComboBox2. Text then
The begin
EB1. Sheets [1]. The Rows [I]. Copy;
EB1. Sheets [2]. The Rows [j]. J PasteSpecial;
J:=j + 1;
end;
end;
EB1. Sheets [2]. Name:=ComboBox2. Text;
EB1. Sheets [2]. Cells [1, 1]. The Select;
EB1. Sheets [2]. The Columns. EntireColumn. AutoFit;
ExcelApp. ActiveWorkBook. Sheets. [2]. UsedRange SaveAs
(ExtractFilePath (OpenDialog1 FileName) + ComboBox2. Text);
end;
Messagebox (handle, 'file split! ', 'prompt', 0 + 64);
Edit1. The Clear;
OpenDialog1. FileName:=' ';
ComboBox1. Items. The Clear;
ComboBox2. Items. The Clear;
ExcelApp. ActiveWorkBook. Save;
ExcelApp. DisplayAlerts:=False;
ExcelApp. Quit;
end;
end;
  • Related