mibuso.com

Microsoft Business Solutions online community
It is currently Tue May 21, 2013 11:13 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Tips&Tricks: Excel Automation
PostPosted: Fri Jul 28, 2000 11:44 pm 
Offline

Joined: Sun Jul 16, 2000 7:01 am
Posts: 161
Location: CH-3322 Schoenbuehl
Country: Switzerland (ch)
I notice that in this forum (and not only ther) the same questions and problems concerning Excel automation are being asked over and over again. So let me share some of my experience with you:

--- DECLARATION ---
Name DataType Subtype Length
xlWorkbooks Automation 'Microsoft Excel 9.0 Object Library'.Workbooks
xlWorksheet Automation 'Microsoft Excel 9.0 Object Library'.Worksheet
xlWorksheetTemp Automation 'Microsoft Excel 9.0 Object Library'.Worksheet
xlApplication Automation 'Microsoft Excel 9.0 Object Library'.Application
xlRange Automation 'Microsoft Excel 9.0 Object Library'.Range
xlWorkbook Automation 'Microsoft Excel 9.0 Object Library'.Workbook
xlBorders Automation 'Microsoft Excel 9.0 Object Library'.Borders
xlHPageBreaks Automation 'Microsoft Excel 9.0 Object Library'.HPageBreaks
xlSheets Automation 'Microsoft Excel 9.0 Object Library'.Sheets

--- OPEN EXCEL ---
CLEAR(xlApplication);
CLEAR(xlRange);
CLEAR(xlWorkbooks);
CLEAR(xlWorkbook);
CLEAR(xlRange);
CLEAR(xlSheets);
CLEAR(xlWorksheet);
CLEAR(xlBorders);

IF CREATE(xlApplication, FALSE) THEN BEGIN // Param FALSE: If excel already started, use existing instance
xlApplication.SheetsInNewWorkbook := 1;
xlApplication.ScreenUpdating(FALSE); //RE01.02


--- note:
{At this point you have two possibilities:
1.Keep Excel visible and update the screen as long as you are developing. This considerably slows down exceution time but you always see what's going on. In case of the crash you know what has been done last and you can close Excel manually}
xlApplication.Visible(TRUE);
xlApplication.ScreenUpdating(TRUE);

{2. If your application is tested, you can turn Excel off while Navision is sending data. This will double the speed of execution. However, if an error occurs, Excel will still be instantiated but will not be visible in the taskbar. Pressing Ctrl-Alt-Del and killing the task will be your only option.
xlApplication.ScreenUpdating(FALSE);
xlApplication.Visible(FALSE);
---

xlWorkbooks := xlApplication.Workbooks;
END
ELSE
ERROR('Could not start Excel');


---------------------------
Procedure OpenExistingXlsWorkbook(FName : Text[250],SheetNr : Integer);

xlWorkbooks := xlApplication.Workbooks;
WorksheetAlreadyOpen := FALSE; // this is a local variable
IF xlWorkbooks.Count > 0 THEN BEGIN
ThisWorkbook := xlApplication.ActiveWorkbook;
WorksheetAlreadyOpen := (ThisWorkbook.FullName = FName);
END;
IF NOT WorksheetAlreadyOpen THEN
xlWorkbooks.Open(FName);
xlWorkbook := xlApplication.ActiveWorkbook;
xlSheets := xlWorkbook.Worksheets;
xlWorksheet := xlSheets.Item(SheetNr);

--- note: A preferred method of mine is to use an existing Excel Book as Template where the user can
define Titles, Layout etc. as he wishes. My application then reads this template file, fills in the data and saves the result under a different name. The above code with "WorksheetAlreadyOpen" makes sure that the Template Book is not being opened twice.

----------------------------
Procedure XlsNewWorkBook (WName : Text[20]);

xlWorkbooks.Add;
xlWorkbook := xlApplication.ActiveWorkbook;
xlWorksheet := xlApplication.ActiveSheet;
xlWorksheet.Name := Name;


--- SAVE EXCEL WORKSHEET ---
Procedure XlsSaveAs(FName : Text[250]);

IF xlWorkbook.FullName = FName THEN // Same filename
xlWorkbook.Save
ELSE BEGIN
IF FILE.EXISTS(FName) THEN // Forced overwrite, in case the File already exists!
IF ERASE(FName) THEN;
xlWorkbook.SaveAs(FName);
END;

--- CLOSE EXCEL ---
Procedure CloseExcel (Action : Option (Visible,PrintAndQuit,Quit));

Case Action of
Action::Visible: Begin
xlApplication.ScreenUpdating(TRUE);
xlApplication.Visible(TRUE);
End;
Action::PrintAndQuit : Begin
xlApplication.ScreenUpdating(TRUE); //force Recalculation
xlWorkbook.PrintOut;
x


Top
 Profile E-mail  
 
 Post subject: Tips&Tricks: Excel Automation
PostPosted: Sat Jul 29, 2000 2:44 am 
Offline
Site Admin

Joined: Sun Nov 07, 1999 8:01 am
Posts: 1900
Location: Wilrijk, Belgium
Country: Belgium (be)
This article has been moved to the new forum Tips & Tricks.


Top
 Profile  
 
 Post subject: Tips&Tricks: Excel Automation
PostPosted: Fri Aug 04, 2000 8:16 pm 
Offline

Joined: Wed Nov 24, 1999 8:01 am
Posts: 37
Location: Germany
Country: Germany (de)
Okay, that is a fine code ...

... but can i do the same with
Winword ??????



------------------
Best regards
Alex Schubert

ERP & Navision

Dolphin Communication Technologies GmbH
Otto-Hahnstr. 1 c
D-69190 Walldorf
<A HREF="mailto:schubert@dolphinct.de">schubert@dolphinct.de</A>
schubert@dolphinct.de
DolphinCT.de


Top
 Profile E-mail  
 
 Post subject: Tips&Tricks: Excel Automation
PostPosted: Mon Nov 27, 2000 6:15 pm 
Offline

Joined: Wed May 17, 2000 7:01 am
Posts: 41
Location: Germany
Country: Germany (de)
Example:

CREATE(Winword); // start Word
Winword.Documents.Add; // new blank page
// Winword.Visible(TRUE); // only for testing, because it is very slow

OnAfterGetRecord()
zeile (name);
zeile (Adress);
leerzeile(1);
zeile ("PLZ Code" + ' ' + Ort);

// picture
IF Bild.HASVALUE THEN BEGIN
Bild.EXPORT('c:\'+"Nr."+'.bmp');
Save1:= FALSE; // linkToFile:=False
save2:= TRUE; // SaveWithDocument:=True
Winword.Selection.InlineShapes.AddPicture('c:\'+"Nr."+'.bmp',Save1,save2);
END;

Winword.Selection.InsertBreak; // new page

OnPostDataItem()
Winword.Visible(TRUE); // Winword visible
Winword.Activate; // Winword aktiv

zeile(text : Text[250])
Winword.Selection.TypeText(text); // Zeile schreiben
leerzeile(1);

leerzeile(Anzahl : Integer)
FOR i := 1 TO Anzahl DO
Winword.Selection.TypeParagraph; // space-lines


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2003 4:58 pm 
Offline

Joined: Thu Aug 15, 2002 7:01 am
Posts: 7
Location: Ostrava, Czech Republic
Country: Czech Republic (cz)
And after all don't forget to CLEAR all instancies, or the excell.exe will be still running on the "Background".


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 2:38 pm 
Offline

Joined: Wed Jun 04, 2003 2:28 pm
Posts: 276
Location: Antwerpen
Country: Belgium (be)
Another way of checking if a Automation variable is created is:

Code: Select all
IF ISCLEAR(autAutomationVariable) THEN BEGIN
  CREATE(autAutomationVariable);
END;

...

CLEAR(autAutomationVariable);

_________________
Now, let's see what we can see.
...
Everybody on-line.
...
Looking good!


Top
 Profile  
 
 Post subject: Put bmp in Excel while using Excel Buffer to export
PostPosted: Sun Jan 02, 2005 12:29 pm 
Offline

Joined: Wed May 12, 2004 5:31 am
Posts: 3
Location: Asia
Hi there,

I have created a program to export to excel using excel buffer. Now the client wants me to add a logo to the document header.

How can I keep my original report while adding a logo to the header?

I've tried :
XlWorkSheet.PageSetup.LeftHeaderPicture.Filename := 'C:\picture.BMP'
which didn't work..

Then
XlWorkSheet.Pictures.Insert('C:\picture.BMP')
which couldn't compile...

Only succeeded with
XlWorkSheet.SetBackgroundPicture('C:\picture.BMP');
which is not what I want!

](*,) I'm very new to all this automation programming. Pls give a hint or two.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 11:54 am 
Offline

Joined: Mon Jan 03, 2005 1:30 pm
Posts: 1
Location: Fa
I dont use the Excel Buffer, but the code that works for me is:

Book:=Excel.Workbooks.Add(-4167);
Sheet:=Excel.ActiveSheet;
xlWorksheet.PageSetup.CenterHeaderPicture.Filename := 'C:\Header.bmp';
Sheet.PageSetup.CenterHeaderPicture.Height := 197;
Sheet.PageSetup.CenterHeaderPicture.Width := 418;
Sheet.PageSetup.CenterHeaderPicture.Brightness := 0.36;
Sheet.PageSetup.CenterHeaderPicture.ColorType := 1;
Sheet.PageSetup.CenterHeaderPicture.Contrast := 0.39;
Sheet.PageSetup.CenterHeaderPicture.CropBottom := 0;
Sheet.PageSetup.CenterHeaderPicture.CropLeft := 0;
Sheet.PageSetup.CenterHeaderPicture.CropRight := 0;
Sheet.PageSetup.CenterHeaderPicture.CropTop := 0;
Sheet.PageSetup.CenterHeader := '&G';

Note: You will have to press Print Preview to view the logo.

PS: Anyone knows how to insert a row into Excel at a given place?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 1:31 pm 
Offline

Joined: Mon Dec 20, 2004 11:33 am
Posts: 18
Location: Manchester
Country: United Kingdom (uk)
Selection.EntireRow.Insert

I think the selection object is part of the application object but I'm not sure, try AppVariable.Selection.EntireRow.Insert or SheetVariable.Selection.EntireRow.Insert. This only inserts a blank row mind, so you will have to put your data into this row after inserting it. You will have to move the cursor to the desired row first too.

_________________
Charleh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 8:53 am 
Offline

Joined: Mon May 23, 2005 6:45 pm
Posts: 7
Location: India
Country: India (in)
8) Thankz. very useful info


Top
 Profile  
 
 Post subject: Automation
PostPosted: Sun Sep 04, 2005 10:50 pm 
Offline

Joined: Wed Aug 24, 2005 5:27 pm
Posts: 78
Location: DUS
Country: Germany (de)
This is nice work to put data out to Excel or Word.
But what about the other way around?

Any Hints and tricks to get Data out of excel into Navision by C/AL code?

_________________
regards,
Michael Schumacher

oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 3:28 pm 
Offline

Joined: Wed Jun 09, 2004 9:06 pm
Posts: 29
Location: Connecticut
Country: United States (us)
Take a look at the Industry Template tool in 3.70B. It has a utility that will take data from Excel and insert in Navision. The key pieces are Table 8601 Mapping Header, Table 8602 Mapping Lines and Codeunit 8601 Mapping Handle. Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:02 pm 
Offline

Joined: Wed Aug 24, 2005 5:27 pm
Posts: 78
Location: DUS
Country: Germany (de)
zarryn wrote:
Take a look at the Industry Template tool in 3.70B.

where can I get this from?
we only have 4.00 since we are a very new partner (not yet completely certified) :?:

_________________
regards,
Michael Schumacher

oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 4:05 pm 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Tue Jul 19, 2005 4:49 pm
Posts: 3836
Location: Olst
Country: Netherlands (nl)
Do you already have access to PartnerSource?

Otherwise I can mail it to you.

_________________
Mark Brummel | Freelance Dynamics NAV (Navision) Developer
Author of the book : Microsoft Dynamics NAV 2009 Application Design

MY BLOG : http://www.brummelds.com


Top
 Profile E-mail WWW  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 5:12 pm 
Offline

Joined: Wed Aug 24, 2005 5:27 pm
Posts: 78
Location: DUS
Country: Germany (de)
Mark Brummel wrote:
Do you already have access to PartnerSource?

not completely, the download rights are not given..... :(

ok I'll send you an email, so that you can answer to that address ;-)

_________________
regards,
Michael Schumacher

oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 3 guests


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 post attachments in this forum


Search for:
Jump to: