Excel dotnet in Excel Buffer table

Roelof
Member Posts: 377
I need to find a solution to update an existing Excel Spreadsheet. There is some code in table 370 (Excel Buffer) that allows a user to write to excel as a new spreadsheet but NOT updating an existing sheet with tabs.
Which dotnet options do I have in order to achieve that?
In older NAV version with Automation it was a lot easier.
Any ideas?
Which dotnet options do I have in order to achieve that?
In older NAV version with Automation it was a lot easier.
Any ideas?
Roelof de Jonghttp://www.wye.com
0
Answers
-
Hello,
There is a function UpdateBook() in table 370 which you can use to update existing workbook.
Below is an example how to add text to D3 cell:ClientFileName := FileManagement.OpenFileDialog('','',FileManagement.GetToFilterText('','*.xlsx')); IF ClientFileName = '' THEN EXIT; ServerFileName := FileManagement.UploadFileSilent(ClientFileName); SheetName := xlBuf.SelectSheetsName(ServerFileName); xlBuf.UpdateBook(ServerFileName,SheetName); xlBuf.SetCurrent(3,3); xlBuf.AddColumn('This cell is populated from Nav',FALSE,'',FALSE,FALSE,FALSE,'',xlBuf."Cell Type"::Text); xlBuf.WriteSheet('',COMPANYNAME,USERID); xlBuf.CloseBook; xlBuf.DownloadAndOpenExcel;
0 -
So, would 'XlBuf.SetCurrent(3,3) refer to Cel D3?
And what options in your example is there to read the Cel?
I need to compare the cel.value before I will write to it.
Roelof de Jonghttp://www.wye.com0 -
To read cell content you have to declare one more Excel Buffer variable and execute ReadSheet() function to get content of the sheet. Then just add to xlBuf cells which you need to update:
xlBufRead.OpenBook(ServerFileName,SheetName); xlBufRead.ReadSheet; xlBuf.UpdateBook(ServerFileName,SheetName); IF xlBufRead.FINDSET THEN REPEAT IF xlBufRead."Cell Value as Text" = 'Your condition' THEN BEGIN xlBuf := xlBufRead; xlBuf."Cell Value as Text" := 'New cell value'; xlBuf.INSERT; END; UNTIL xlBufRead.NEXT = 0; xlBuf.WriteSheet('',COMPANYNAME,USERID); xlBuf.CloseBook; xlBuf.DownloadAndOpenExcel;
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