How to Merge Excel Cells in NAV 2016 with DotNet variables.

borjags1985
Member Posts: 7
I want to merge Excel cells with Dotnet variables from the Excel Buffer table but I can not find clear information about that.
I could change Font color and size and define cell borders too, but I have not been able to merge cells.
Has anyone seen something about that?
Thanks!!
I could change Font color and size and define cell borders too, but I have not been able to merge cells.
Has anyone seen something about that?
Thanks!!
0
Answers
-
Hey,
Check out this link it may help you.
[url="http://forum.mibuso.com/discussion/15266/merging-cells-in-excel-using-excel-
buffer"]forum.mibuso.com/discussion/15266/merging-cells-in-excel-using-excel-buffer[/url]
This piece of code
XlBook := XlApp.Workbooks.Open(FileName);
//Transfering Data to Microsoft Excel:
XlSheet:= XlApp.ActiveSheet;
XlSheet.Range('A1:A2').Cells.Merge;
XlSheet.Range('A1').HorizontalAlignment := -4108;Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
I'm trying to set that code but it doesn't work.
On table 370, before calling GiveUserControl function and after calling OpenExcel, I call a new function called fMergeCells. This function use the vars in the table, so they must be initialized.
That is my function:
fMergeCells(pInitRange : Text;pEndRange : Text)
IF (pInitRange = '') OR (pEndRange = '') THEN
ERROR(ErrorText50000);
XlWrkSht := XlApp.ActiveSheet;
XlWrkSht.Range(pInitRange + ':' + pEndRange).Cells.Merge('');
And this is the error:
"A Dotnet variable has not been instantiated. Attempting to call Cells in Table Excel Buffer: fMergeCells"0 -
Finally I have been able to solve the problem. In addition, i have put the code in the 370 table to standarize it. So, firstly the sheets are writen with TempExcelBuffer.WriteSheet. After that I call a function to apply the format to the Range (in this function you can insert any code that can be managed with the Range DotNet var).
What I have done in that function is to create another var for Range Method: XlRange DotNet Microsoft.Office.Interop.Excel.Range.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' .
This var has to be instanziated like this:
XlWrkSht := XlWrkBk.Worksheets.Item(pWrkShtName);
After that I instanziate the Range var:
XlRange := XlWrkSht.Range('A1:B1');
Finally I use any function in that var:
XlRange.Cells.Merge(TRUE);
XlRange.HorizontalAlignment := 1;
XlRange.VerticalAlignment := 1;
1 -
You have to set the RunOnClient property of Range DotNet var to YES.1
-
This was assumed as being already done0
-
Hi, should this work in NAV 2015?
I am getting on run time:
******
A DotNet variable has not been instantiated. Attempting to call Microsoft.Office.Interop.Excel.Range.Cells in Table Excel Buffer: MergeRange
******
0 -
Same error here as @chachitano@hotmail.com . Can someone tell us how to solve the problem ? I have tried many ways to instantiate it, but without a positive result.0
-
@chachitano@hotmail.com I solve it .. just make the function , for the merge , to be called from PostOpenExcel() function.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