I want import in FExcelIO: TAdvGridExcelIO; component *.xls file with 7 sheets. how do this right?
methot FExcelIO.XLSImport(aFileName); - work in only in visual component and I noticed that the component works differently with the dynamic creation of.
Example:
procedure TForm1.btn1Click(Sender: TObject);
var
FExcelIO: TAdvGridExcelIO;
begin
FExcelIO := TAdvGridExcelIO.Create(nil);
FExcelIO.XLSImport('d:\xxx.xls');
FExcelIO.AdvGridWorkbook := advgrdwrkbk1;
end;
Lead to error: "Exception with message 'There is no AdvStringGrid assigned to this component'."
I write this function but I'm not sure that I did everything right.
procedure TAdvSpreadBook.LoadFromFile(const aFileName: string);
var
i: Integer;
G: TAdvSpreadGrid;
begin
FExcelIO.XLSImport(aFileName);
exit;
while FPageControl.PageCount > 0 do
FPageControl.Pages[0].Free;
FExcelIO.LoadSheetNames(aFileName);
for I := 0 to FExcelIO.SheetNamesCount - 1 do
begin
G := NewGrid(FExcelIO.SheetNames);
FExcelIO.AdvStringGrid := G;
FExcelIO.XLSImport(aFileName);
end;
end;
procedure TAdvSpreadBook.SaveToFile(const aFileName: string);
var
i: Integer;
begin
for I := 0 to FExcelIO.SheetNamesCount -1 do
begin
FExcelIO.AdvStringGrid := GetGrids(I);
FExcelIO.XLSExport(aFileName, FExcelIO.SheetNames);
end;
end;
If you use TAdvStringGrid, you'll indeed need to loop through all sheets and import sheet per sheet by using the sheetname parameter in the XLSImport() call.
When you use a TAdvGridWorkbook that you assign to TAdvGridExcelIO.AdvGridWorkbook, then TAdvGridExcelIO should do this automatically for you.