Updating Excel without losing formatting

radek.bb
Member Posts: 49
Excel Buffer provides a functionality to update worksheet - but the trick is: it is forcing new cell Decorator during update - function WriteCellValue looks like this:
I could change it to something like this:
And it almost works - the destination formatting is preserved - but the value is indeed put as text - not as the type expected in the cell.
The only way I found to do this is to use ancient-old approach - from Nav2009 when Excel Buffer was implemented by Excel automation.
But obviously the solution is extremely slow and requires Excel installed on client machine (cannot be used on server side).
So the question:
Is it a way to preserve formatting while updating values on selected cells?
I would imagine that we should either get the current cell Decorator and use it in existing code - or use some other function to update cell value only....
[External] WriteCellValue(ExcelBuffer : Record "Excel Buffer Advanced") WITH ExcelBuffer DO BEGIN GetCellDecorator(ExcelBuffer, Decorator); CellTextValue := "Cell Value as Text"; OnWriteCellValueOnBeforeSetCellValue(Rec,CellTextValue); CASE "Cell Type" OF "Cell Type"::Number: XlWrkShtWriter.SetCellValueNumber("Row No.",xlColID,CellTextValue,NumberFormat,Decorator); "Cell Type"::Text: XlWrkShtWriter.SetCellValueText("Row No.",xlColID,CellTextValue,Decorator); "Cell Type"::Date: XlWrkShtWriter.SetCellValueDate("Row No.",xlColID,CellTextValue,NumberFormat,Decorator); "Cell Type"::Time: XlWrkShtWriter.SetCellValueTime("Row No.",xlColID,CellTextValue,NumberFormat,Decorator); ELSE ERROR(Text039) END;
I could change it to something like this:
[External] WriteCellValue(ExcelBuffer : Record "Excel Buffer Advanced") WITH ExcelBuffer DO BEGIN GetCellDecorator(ExcelBuffer, Decorator); CellTextValue := "Cell Value as Text"; OnWriteCellValueOnBeforeSetCellValue(Rec,CellTextValue); // extra part to update value without changing decorator IF UpdateValueOnly THEN XlWrkShtWriter.UpdateCellValueText("Row No.",xlColID,CellTextValue) ELSE // end of extra part CASE "Cell Type" OF "Cell Type"::Number: XlWrkShtWriter.SetCellValueNumber("Row No.",xlColID,CellTextValue,NumberFormat,Decorator); "Cell Type"::Text: XlWrkShtWriter.SetCellValueText("Row No.",xlColID,CellTextValue,Decorator); "Cell Type"::Date: XlWrkShtWriter.SetCellValueDate("Row No.",xlColID,CellTextValue,NumberFormat,Decorator); "Cell Type"::Time: XlWrkShtWriter.SetCellValueTime("Row No.",xlColID,CellTextValue,NumberFormat,Decorator); ELSE ERROR(Text039) END;
And it almost works - the destination formatting is preserved - but the value is indeed put as text - not as the type expected in the cell.
The only way I found to do this is to use ancient-old approach - from Nav2009 when Excel Buffer was implemented by Excel automation.
But obviously the solution is extremely slow and requires Excel installed on client machine (cannot be used on server side).
So the question:
Is it a way to preserve formatting while updating values on selected cells?
I would imagine that we should either get the current cell Decorator and use it in existing code - or use some other function to update cell value only....
1
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