How to export keeping the zeros(0001) to Excel?

NavCoder
Member Posts: 22
How can I export a number to Excel, keeping the zeros at the beginning, like 0001.
I know that if I add a char to the beginning of the number, it will export all the zeros after that char, but I don't want to add any char.
How can I do it?
I know that if I add a char to the beginning of the number, it will export all the zeros after that char, but I don't want to add any char.
How can I do it?
MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;
IF NOT Help THEN
Exit;
0
Answers
-
Try with:
txtTheNumber := '''' + FORMAT(TheNumber); // This meaning you add a ' before the string. To put a ' in a string, you need to double it, so you need to put 4 ' to get a string with a ' in it.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I've tried to add a ' creating a text constant with that value, but the Excel doesn´t ignored the '. :-k
This number is a code field, doesn´t need the FORMAT.MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
did you use 4 single quotes?
''''NavCoder wrote:I know that if I add a char to the beginning of the number, it will export all the zeros after that char, but I don't want to add any char.
Why? :-k0 -
so your exporting from Nav->CSV File->Import Excel
You can go from nav to Excel directly using the excel bufferThis number is a code field, doesn´t need the FORMAT.SomeTextVariable := ''''+Item."Item UPC/EAN Number";
0 -
Hi,
Just tested how you can get 0001 into Excel.
Just fill a line in table Excel Buffer (370) as follows:
Row No. 1
Column No. 1
xlRowID 1
xlColID A
Cell Value as Text 0001
The @ turns the cell-properties into Text.
Create a codeunit to test it:
recExcelBuffer.CreateBook;
recExcelBuffer.CreateSheet('1', '2', '3', '4');
recExcelBuffer.GiveUserControl;
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
Savatage wrote:so your exporting from Nav->CSV File->Import Excel
Even with code fields - I use this code to export UPC codesSomeTextVariable := ''''+Item."Item UPC/EAN Number";
And the Excel ignores the quote?MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
NavCoder wrote:And the Excel ignores the quote?
What do you mean by that? Do you want excel to ignore it or not? :-k0 -
Yes, I just want the Excel to write the number with zeros.MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
tinoruijs wrote:Hi,
Just tested how you can get 0001 into Excel.
Just fill a line in table Excel Buffer (370) as follows:
Row No. 1
Column No. 1
xlRowID 1
xlColID A
Cell Value as Text 0001
The @ turns the cell-properties into Text.
Create a codeunit to test it:
recExcelBuffer.CreateBook;
recExcelBuffer.CreateSheet('1', '2', '3', '4');
recExcelBuffer.GiveUserControl;
This might work but when using on a different database, the user always has to add that record into the Excel Buffer Table.MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
how you are are exporting the data?
-
-Dataport
-CodeUnit
-Report
-Excel Buffer
-Copy & Paste
I'm not sure what's not working for you - these are proven metods that work.0 -
Dataport.MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
I did a test exporting the same field "UPC" as a test
Once alone & Once with the upc := ''''+Item."UPC Code"
I see when you click on the CSV file the ' does show in column when opened. But I also Noticed that if you name the file type TXT instead of CSV that an unmodified field will retain it's leading Zero.
Then when you import the file into excel just make sure the Format->Cells->Text for that column.
How are you importing that data? Data->Import External Data?
there you can define the type of field it is.in your case you want it text not number.
If you go right from Nav->Excel Buffer->Excel the 4 single quotes works great.0 -
I´m just exporting with a dataport, I´m giving the .csv manually when I´m writing the name of the file.MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
NavCoder wrote:tinoruijs wrote:Hi,
Just tested how you can get 0001 into Excel.
Just fill a line in table Excel Buffer (370) as follows:
Row No. 1
Column No. 1
xlRowID 1
xlColID A
Cell Value as Text 0001
The @ turns the cell-properties into Text.
Create a codeunit to test it:
recExcelBuffer.CreateBook;
recExcelBuffer.CreateSheet('1', '2', '3', '4');
recExcelBuffer.GiveUserControl;
This might work but when using on a different database, the user always has to add that record into the Excel Buffer Table.
No they don't have to do that.
You can make a function that fills the Excel Buffer table. Like in report 82. It uses the Excel Buffer as a temporary table.
Instead of starting the dataport you could use the function export to excel.
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
It seems my Excel-solution is a bit off topic..
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
NavCoder wrote:I´m just exporting with a dataport, I´m giving the .csv manually when I´m writing the name of the file.
Did you try giving it a .TXT manually when writing the filename?
then open excel Data->Import External Data.
If you looking for simple what's easier than using the export to excel feature?You can make a function that fills the Excel Buffer table. Like in report 82. It uses the Excel Buffer as a temporary table.
Instead of starting the dataport you could use the function export to excel.0 -
When I say simple, doesn´t mean easier, I have 2 dataports(Import/Export).
I´m just looking for a way to let me write the number correctly, just changing
a property or adding a line of code.
If isn´t possible I will think about using other objects and create functions to solve the problem.
Thks for your support.MBS Navision C/Side Introduction Certified
IF NOT Help THEN
Exit;0 -
I'm just saying that if you look at the TXT or CSV file you created using NOTEPAD you will see the leading Zeros are there. It is getting lost on the method you are using to open the file in Excel.
If my CODE is 0001 for a customer for example and I export the Cust No using a dataport to a TXT or CSV file I see "0001" which is correct.
My test dataport produced a file like this (item# & UPC Code)
"10030","062765350127"0 -
just take a tour of Excel Buffer..
good luck
:roll:MCSD
Attain Navision0 -
Hi Navcoder,
your issue is solved ? i am also facing the same problem. For ex: in navision suppose customer number is 00778 then i am using dataport to export this value into CSV but after exporting the value in Excel is 778 it will mislead the information.
if table contain huge data it is unable to check and edit the data..
Hope experts can understand the situation . How to rectify the same ?Luv,
Dynamics Lover0 -
Hi,
below code from savatage works like a charm
txtTheNumber := '''' + FORMAT(TheNumber); in onbeforeexportrecord() i kept this code it worked...
below are my result
Formated(using code) No:(normal no without code)
000114 114
Thanks for the help....Luv,
Dynamics Lover0 -
just wanted to thank the board for the @ in the NumberFormat - just what i needed!kind of fell into this...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