NAV 2013 R2 Extending Excel Buffer with openXml

troydohrman
Member Posts: 2
I'm trying to add functionality to the excel buffer table in NAV 2013 R2. I want to be able to set the column width. I'm following the example in the following document...
https://mbs.microsoft.com/files/partner ... 2013R2.pdf
I've recreated it exactly but when I call the SetColumnWidth function in my add-in from the WriteCellValue trigger, the Columns variable is Null and causes an error.
Here is the NAV code in the ExcelBuffer table...
Here is the c# add-in code I created...
Why would the columns variable be Null?
https://mbs.microsoft.com/files/partner ... 2013R2.pdf
I've recreated it exactly but when I call the SetColumnWidth function in my add-in from the WriteCellValue trigger, the Columns variable is Null and causes an error.
Here is the NAV code in the ExcelBuffer table...
LOCAL WriteCellValue(ExcelBuffer : Record "Excel Buffer") WITH ExcelBuffer DO BEGIN GetCellDecorator(Bold,Italic,Underline,Decorator); CASE "Cell Type" OF "Cell Type"::Number: XlWrkShtWriter.SetCellValueNumber("Row No.",xlColID,"Cell Value as Text",NumberFormat,Decorator); "Cell Type"::Text: XlWrkShtWriter.SetCellValueText("Row No.",xlColID,"Cell Value as Text",Decorator); "Cell Type"::Date: XlWrkShtWriter.SetCellValueDate("Row No.",xlColID,"Cell Value as Text",NumberFormat,Decorator); "Cell Type"::Time: XlWrkShtWriter.SetCellValueTime("Row No.",xlColID,"Cell Value as Text",NumberFormat,Decorator); ELSE ERROR(Text039) END; // Cust1.00 Start IF "Column Width" > 0 THEN BEGIN myOpenXml.SetColumnWidth("Column No.", "Column Width", XlWrkShtWriter.Worksheet); END; // Cust1.00 End END;
Here is the c# add-in code I created...
public static void SetColumnWidth(uint columnIndex, decimal width, Worksheet openXmlWorksheet) { var columns = openXmlWorksheet.GetFirstChild<Columns>(); var column = columns.ChildElements.FirstOrDefault(t => (t is Column) && (t as Column).Min <= columnIndex && (t as Column).Max <= columnIndex) as Column; if (column == null) { column = new Column() { Min = columnIndex, Max = columnIndex }; columns.Append(column); } column.CustomWidth = true; column.Width = Convert.ToDouble(width); }
Why would the columns variable be Null?
0
Comments
-
My guess is that the you use a wrong value as first parameter to SetColumnWidth.
You use "Column No." the example uses xlColID
/Juha0 -
Rather than working with OpenXML or the limitations of microsoft's wrapper, we've used the ClosedXML library to extend the excel buffer functionality which has worked very well. Generally we've structured it to work after the fact. i.e. new properties to call for column widths and other formatting that buffer the changes (or save them in new fields), then we let NAV do its usual thing to create the book, then we reopen the file using ClosedXML to apply the format changes before it's downloaded to the client and opened.Rob Hansen
http://www.epimatic.com0
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