Formula's in Excel using automation

Luc_VanDyck
Member, Moderator, Administrator Posts: 3,633
When working with formula's in Excel using automation, you have to know what language-version of Excel is installed (English, Dutch, French, etc.) in order to write your formula (eg. SUM/SOM/SOMME, ROUND/AFRONDEN/...).
The function
There must be a way to use formula's independant of the language, so you only have to write them in English.
How can you do this?
The function
xlApp.International(lxlCountryCode));(with lxlCountryCode = 1) returns the language being used.
There must be a way to use formula's independant of the language, so you only have to write them in English.
How can you do this?
No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
0
Comments
-
Anybody ever sorted out how to do this?
If I do the following in Excel Range("A1").Formula = "=Sum(B1:B10)", A1 will contain the formula in the local user his language.
If I do the same in Navision, it A1 always contains "=Sum(B1:B10)", it does not translate the formula.
It would be SUPER, and I mean super super handy to get this working since we have EMEA offices where all users have Excel in their native language and I do not want to start looking at the Excel version of the user and start saving all formulas in all languages.0 -
I've finally found an easy way to do this, I'll put the code here as soon as I have a free minute!0
-
Still no free minute? Fri - Tue... hmm... :-#It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.0
-
Hi AntidotE,
I was actually entering an article about this on my blog when I got a message you replied to this post :-).
You can read how I solved it on my blog article here: http://www.noisyvan.com/2008/10/09/make-exporting-excel-formulas-fully-multilanguage-aware/.
Is it allowed to put just a link to this article or should I cope the content over here too?0 -
mart1n0 wrote:Is it allowed to put just a link to this article or should I cope the content over here too?No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
-
Actually, old link is incorrect already, new one: http://noisyvan.wordpress.com/2008/10/0 ... uage-aware
Anyway, I'll take a time and post this blog page here (screenshots will be from blog too):Make Exporting Excel Formulas Fully Multilanguage Aware
October 9, 2008
I have been struggling with exporting data from Dynamics NAV to Excel Spreadsheets including formulas lately. I had the problem with a custom developed export to excel so I checked the code in the Excel Buffer table to see how standard Navision solved the problem only to see that the problem also existed in standard NAV too.
Let’s explain the problem first. What happens is that for people with a Microsoft Office version in Language A and a Dynamics NAV client in language B, Navision does not translate the formulas correctly. You can reproduce it as follows.
Make sure the language of your Dynamics NAV client and of Microsoft Office are different. Open your Dynamics NAV client go to the Budget form and run the “Export to Excel …” function. You’ll see that the formulas aren’t be translated as they should, giving errors in Excel.
English NAV Client and Spanish Office, wrong formula
Standard Dynamics NAV uses multilanguage text constants to translate the Formulas in the Excel Buffer table. The problem is that this only works if your Microsoft Office language equals your Dynamics NAV Client language and on top of this, for it to work you need to translate ALL the formulas you want to use to ALL the languages you want to use. Not a fun thing to do but feel free to use a page like this fonctions XL en 9 langues or this Microsoft Excel function translations to get started putting all your formulas into multilanguage text constants.
Since we have some workstations where the Dynamics NAV client and Microsoft Office use a different language, I was looking for something better and this post on mibuso handed me the solution. Below I put the code if you want this feature to work for the Excel Buffer table but you’ll see that it is easy to adopt it to all of you custom code that exports to Excel with formulas.
Table 370 – Excel Buffer
Add the following local variables to the CreateSheet function:- autScriptControl Automation variable with SubType ‘Microsoft Script Control 1.0′.ScriptControl
- txtCode Text variable with Length 1024
- autDictionary Automation variable with Subtype ‘Microsoft Scripting Runtime’.Dictionary
- txtFormula Text variable with Length 1024
- intI Integer variable
Change to code of the CreateSheet function as below:XlWrkSht.Name := SheetName; IF ReportHeader <> '' THEN XlWrkSht.PageSetup.LeftHeader := STRSUBSTNO('%1%2%1%3%4',GetExcelReference(1),ReportHeader,CRLF,CompanyName); XlWrkSht.PageSetup.RightHeader := STRSUBSTNO(Text006,GetExcelReference(2),GetExcelReference(3),CRLF,UserID2); XlWrkSht.PageSetup.Orientation := XlLandscape; IF FIND('-') THEN BEGIN //CRQ.001 start insert CREATE(autDictionary); CREATE(autScriptControl); //CRQ.001 end insert REPEAT RecNo := RecNo + 1; Window.UPDATE(1,ROUND(RecNo / TotalRecNo * 10000,1)); IF NumberFormat <> '' THEN XlWrkSht.Range(xlColID + xlRowID).NumberFormat := NumberFormat; //CRQ.001 delete start // IF Formula = '' THEN // XlWrkSht.Range(xlColID + xlRowID).Value := "Cell Value as Text" // ELSE // XlWrkSht.Range(xlColID + xlRowID).Formula := GetFormula; //CRQ.001 delete end //CRQ.001 start insert IF Formula = '' THEN XlWrkSht.Range(xlColID + xlRowID).Value := "Cell Value as Text" ELSE BEGIN txtFormula := GetFormula(); txtCode :='objCell.Formula=objList.Item(1);'; intI := 1; autScriptControl.Language := 'JScript'; autScriptControl.AddObject('objCell', XlWrkSht.Range(xlColID + xlRowID));// Add excel cell object autScriptControl.AddObject('objList', autDictionary); // Add dictionary object autDictionary.Add(intI,txtFormula); // Add formula to dictionary object autScriptControl.ExecuteStatement(txtCode); // Execute javascript autDictionary.RemoveAll(); // Remove item from dictionary autScriptControl.Reset(); // Reset Script object for next using END; //CRQ.001 end insert[/b]IF Comment <> '' THEN XlWrkSht.Range(xlColID + xlRowID).AddComment := Comment; IF Bold THEN XlWrkSht.Range(xlColID + xlRowID).Font.Bold := Bold; IF Italic THEN XlWrkSht.Range(xlColID + xlRowID).Font.Italic := Italic; XlWrkSht.Range(xlColID + xlRowID).Borders.LineStyle := XlLineStyleNone; IF Underline THEN XlWrkSht.Range(xlColID + xlRowID).Borders.Item(XlEdgeBottom).LineStyle := XlContinuous; UNTIL NEXT = 0; //CRQ.001 start insert CLEAR(autDictionary); CLEAR(autScriptControl); //CRQ.001 end insert[/b]XlWrkSht.Range(GetExcelReference(5) + ':' + xlColID + xlRowID).Columns.AutoFit; END;
Let’s have a look at the “Export to Excel …” function on the Budget form again.
English NAV Client and Spanish Office, correct formula
That’s all, it is that simple, no more text constants, no more looking for translations of a formula, just put all your fomulas in English and let Excel do the work. Please let me know if you know a faster/better/cleaner way to do this.It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.0 -
Even though this post is rather old, here's how to handle this.
https://ricardomoinhos.com/excel-buffer-detect-excels-language/
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