BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to - in Excel

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
max
Guest





PostPosted: Mon Jun 13, 2005 4:46 pm    Post subject: How to - in Excel Reply with 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



Back to top
Broeden
Guest





PostPosted: Fri Jun 17, 2005 4:57 am    Post subject: Re: How to - in Excel Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.