NAV 2013 - Modify Excel Buffer to apply border with OpenXML

Damien_DINE
Member Posts: 2
Hello,
I try to use Excel Buffer to create an Excel file with format modifications to apply. More specially, to have cells with borders. After many tries and searches, i have modified the function GetCellDecorator and add this lines at the end :
Border := XlWrkShtWriter.DefaultCellDecorator.Border.CloneNode(TRUE);
BorderColor := BorderColor.Color;
BorderColor.Auto:=BooValue.FromBoolean(TRUE);
Border.LeftBorder.Style:=BorderStyle.Thin;
Border.LeftBorder.Color:=BorderColor;
Decorator.Border:=Border;
The variables created are :
Border DocumentFormat.OpenXml.Spreadsheet.Border
BorderColor DocumentFormat.OpenXml.Spreadsheet.Color
BorderStyle DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues
BooValue DocumentFormat.OpenXml.BooleanValue
But, i have this error raising : DocumentFormat.OpenXML.Spreadsheet.LeftBorder.set_style failed with this message. The type of one or more arguments does not match the method's parameter type.
Does someone know what i do wrong?
Thanks
I try to use Excel Buffer to create an Excel file with format modifications to apply. More specially, to have cells with borders. After many tries and searches, i have modified the function GetCellDecorator and add this lines at the end :
Border := XlWrkShtWriter.DefaultCellDecorator.Border.CloneNode(TRUE);
BorderColor := BorderColor.Color;
BorderColor.Auto:=BooValue.FromBoolean(TRUE);
Border.LeftBorder.Style:=BorderStyle.Thin;
Border.LeftBorder.Color:=BorderColor;
Decorator.Border:=Border;
The variables created are :
Border DocumentFormat.OpenXml.Spreadsheet.Border
BorderColor DocumentFormat.OpenXml.Spreadsheet.Color
BorderStyle DocumentFormat.OpenXml.Spreadsheet.BorderStyleValues
BooValue DocumentFormat.OpenXml.BooleanValue
But, i have this error raising : DocumentFormat.OpenXML.Spreadsheet.LeftBorder.set_style failed with this message. The type of one or more arguments does not match the method's parameter type.
Does someone know what i do wrong?
Thanks
0
Comments
-
I wonder did you ever get this to work?
The only real limitation stopping me from using the now native openxml for excel output is not being able to do borders...
Bruce Anderson0 -
asmilie2b wrote:I wonder did you ever get this to work?
The only real limitation stopping me from using the now native openxml for excel output is not being able to do borders...
Create an excel with OpenXml is a very complex task.
We re-implemented the excel buffer with closedxml (https://closedxml.codeplex.com/) and managing borders, cell merge, etc is more easy.
MatteoReno Sistemi Navision Developer0 -
This is my first comment here... here we go!!!
I’ve found a solution. I was thinking about how Excel Buffer do “underline”, in fact is a BottomBorder… the solution was copying the style of BottomBorder to other border sides:
Local Variable:Name DataType Subtype CustomBorder DotNet DocumentFormat.OpenXml.Spreadsheet.Border
Function that replace Excel Buffer GetCellDecorator:LOCAL GetCustomCellDecorator(IsBold : Boolean;IsItalic : Boolean;IsUnderlined : Boolean;HasBorder : Boolean;VAR Decorator : DotNet "Microsoft.Dynamics.Nav.OpenXml.Spreadsheet.CellDecorator") GetCellDecorator(IsBold, IsItalic, (IsUnderlined OR HasBorder), Decorator); IF HasBorder THEN BEGIN CustomBorder := Decorator.Border.CloneNode(TRUE); CustomBorder.TopBorder.Style := CustomBorder.BottomBorder.Style; CustomBorder.RightBorder.Style := CustomBorder.BottomBorder.Style; CustomBorder.LeftBorder.Style := CustomBorder.BottomBorder.Style; Decorator.Border := CustomBorder; END;
I’ve spend a lot of time with this problem… I hope help someone with this.0 -
Hi pjllaneras,
Thank you for your solution
However, for me, my XlWrkShtWriter.DefaultUnderlinedCellDecorator created a top, left and right border but no bottom border which I thought was a bit weird
However, the princple was the same as I could just declare a bottom border by using the border objects top border (or left or right), so it all worked out for me in the end
Thanks
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