Saving Excel files

ls
Member Posts: 33
Hello,
I should create a xls file to export data and save it in a given folder. How could I do it? I'm using 5.0SP1 version.
Thanks
ls
I should create a xls file to export data and save it in a given folder. How could I do it? I'm using 5.0SP1 version.
Thanks
ls
0
Comments
-
Automation is one approach.
create a form which asks the user the path to the folder
Create an excel app, give it a new workbook.
Give your workbook a name and give it a sheet.
export your data to the sheet.
Save the workbook in the folder0 -
I used automation and Excel Buffer Table (370) to fill my Excel file, then, to save it I wrote:
CREATE(XlApp); (also without creating Xlapplication it returns the same error)
XlWrkBk.SaveAs(NomeFile);
but it says me that the Automation variable has not been instantiated.
I could I solve this problem?
ls0 -
This is a codesnippet from an codeunit I downloaded here at Mibuso
IF ISCLEAR(XlApp) THEN IF NOT CREATE(XlApp,TRUE) THEN ERROR(Text000); XlApp.Visible(FALSE); XlBook := XlApp.Workbooks.Add(-4167);
This is from the function createbook.
As you can see you forgot to add the workbook to your application0 -
Sorry, but I can't understand, in fact SaveAs is a method in Workbook and not in Workbook and I only can specify, XlApp.Workbooks and not XLApp.Workbook. So, I could add the Workbook to XlApp, but I can't save it. Where is my error?
ls0 -
xlapp.workbooks is a collection of workbooks.
when you use xlWrkBk := xlapp.workbooks.add(-4167), you let your xlApp create a new workbook and he puts it in the workbooks collection, it also assignes the newly created workbook to your xlWrkBk.
Now you can save your xlWrkBk with the saveAs function.
edit
make sure the SaveAs parameter is something like "C:\map\wrkbk.xls"0 -
What should I do if I have to loop on saving Excel File
Repeat FileName:='C:\'+IdSalesperson+'.xls'; ExcelBuffer.Save(FileName); Until rec.Next =0;
and This is my Save Function That I created in the ExcelBuffer table:CLEAR(XlApp); IF NOT CREATE(XlApp,TRUE) THEN //2- Create instance Excel CREATE(XlApp); XlApp.Visible(FALSE); XlWrkBk := XlApp.Workbooks.Add; XlWrkSht:= XlApp.ActiveSheet; //--- SAVE EXCEL WORKSHEET --- IF XlWrkBk.FullName = FileName THEN // Same filename XlWrkBk.Save ELSE BEGIN IF FILE.EXISTS(FileName) THEN // Forced overwrite, in case the File already exists! IF ERASE(FileName) THEN; XlWrkBk.SaveAs(FileName); END;
the problem is that I have to confirm all the time if my excel file exists, if I have 1000 records I'll have to click yes to the message do you want to save the existent file yes no cancelRegards
Hanen TALBI0 -
Yes, is there a workaround for the confirmation dialog from Excel to save changes? With the exception of cancel it really doesn't matter if I say yes or no to saving the changes. This code exists in a dataport so it immediately tries to use the txt file to import and if I choose cancel it will tell me that the file is already in use. I would like to avoid this dialog prompt if at all possible:
Command := (filepath\filename.xls); IF WSHell.FileExists(Command) THEN WSHell.CopyFile(Command,(filepath1\filename.xls)) ELSE ERROR('File does not exist in the (filepath) subdirectory'); xlWorkbooks := xlApp.Workbooks; xlWorkbooks.Open(Command); xlApp.ScreenUpdating(FALSE); xlApp.Visible(FALSE); xlWorkbook := xlApp.ActiveWorkbook; xlWorksheet := xlApp.ActiveSheet; xlRange := xlWorksheet.Range('1:1'); xlRange.Delete(); xlRange := xlWorksheet.Range('AO:AO'); xlRange.Clear(); xlWorkbook.SaveAs((filepath\filename.txt),6); xlWorkbook.Close; xlApp.Quit; WSHell.DeleteFile(Command,TRUE);
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions