 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
max Guest
|
Posted: Mon Jun 13, 2005 4:46 pm Post subject: How to - in Excel |
|
|
Hi,
I want to programatically show/hide one or more Excel sheets and print them.
Any example would be appreciated.
Is there any good book about this?
Thanks.
max
|
|
| Back to top |
|
 |
Broeden Guest
|
Posted: Fri Jun 17, 2005 4:57 am Post subject: Re: How to - in Excel |
|
|
"max" <max@ab> wrote:
| Quote: | Hi,
I want to programatically show/hide one or more Excel sheets and print them.
Any example would be appreciated.
Is there any good book about this?
Thanks.
max
Hi, |
Check this procedure. Prints the tab named sCompany in workbook WorkOrder.XLS.
Hope it helps.
/Broeden
procedure TForm_ReportMyWay.PrintWorkOrder(sCompany: string; sSerialNo: string;
bBatch: Boolean);
var
SpecialSheetFound: Boolean;
i: Integer;
const
xlWBATWorksheet = -4167;
var
XLApp, xlWB, Sheet: OLEVariant;
begin
XLApp := CreateOleObject('Excel.Application');
try
xlWB := XLApp.Workbooks.Open(ExtractFilePath(Application.ExeName) + 'ReportWorkOrder.XLS');
// Hide Excel
XLApp.Visible := ShowExcel;
Sheet := XLApp.Workbooks['WorkOrder.XLS'].WorkSheets['Data'];
CopyDataToExcel(Sheet, DM.ADOTable_Reklamations, 'A', 'B');
CopyDataToExcel(Sheet, DM.ADOTable_Customers, 'C', 'D');
CopyDataToExcel(Sheet, DM.ADOTable_ContactName, 'E', 'F');
Sheet.Range['G2'] := 'Serienr';
Sheet.Range['H2'] := NES(sSerialNo);
// Check if tab exists
SpecialSheetFound := False;
for i := 1 to XLApp.sheets.count do
if sCompany = XLApp.sheets[i].name then
SpecialSheetFound := True;
// Print sCompanytab otherwise default tab
if ReportDoPrint then
if bBatch then
XLApp.WorkSheets['Batch'].PrintOut
else if SpecialSheetFound then
XLApp.WorkSheets[sCompany].PrintOut
else
XLApp.WorkSheets['Default'].PrintOut;
{
if (FieldByName('WorkOrderName').Value = '')
XLApp.WorkSheets['Default'].PrintOut;
else
XLApp.WorkSheets[FieldByName('WorkOrderName').Value].PrintOut;
}
// Only for test
// XLApp.Save;
if ShowExcel then
ShowMessage('Tryck OK för att stänga Excel och fortsätta!');
finally
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
end;
end;
end;
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|