Importing CSV Files

myanilkumar
Member Posts: 108
Hi All,
I just need to Import CSV files. I cannot use dataports because it must be run by Job Queue through NAS.
So, I need a write a Codeunit for importing the file.
If any one of have a sample code please share.
Thanks.
Anil
I just need to Import CSV files. I cannot use dataports because it must be run by Job Queue through NAS.
So, I need a write a Codeunit for importing the file.
If any one of have a sample code please share.
Thanks.
Anil
0
Comments
-
Hi,
Try these:
Use common diaglog to get the file path
txtDir := cduCDMgmt.OpenFile('Select File','',4,'*.csv,0);
Use Record Table to store the file info
RecFile.SETRANGE(Path, GetFolderDir(txtDir));
RecFile.SETFILTER(Name, GetFileName(txtDir));
Use Excel Buffer table to store and read the data
//to get the txtFileName use COPYSTR function in RecFile.Name //sample txtFileName := COPYSTR(RecFile.Name, 1, 5)
//to get the txtSheetName use COPYSTR in RecFile.Name
recExcelBuffer.OpenBook(txtFileName, txtSheetName);
recExcelBuffer.ReadSheet();
:thumbsup: rock on!!!Thinking, programming, coding, developing == Music!0 -
Hi,
Thanks a lot for reply. The Excelbuffer.Readsheet will update the records in Excel Buffer Tables by Rows & Columns?
Please let me know.
Regards,
Anil0 -
After opening the csv file in code below:
recExcelBuffer.OpenBook(txtFileName, txtSheetName); //opening the csv file using excel to easily read the data ;p
the ExcelBuffer table will be updated and conatins the data on your csv file.
The recExcelBuffer.ReadSheet will Read all records in ExcelBuffer table.Thinking, programming, coding, developing == Music!0 -
Hi,
Once again Thanks for the reply. Is there any way to get the Name of the sheet?
Please advise.0 -
Your Welcome My Friend
The sheet name is the csv file name itself, try to open ur csv file then you will see the sheet name.
Use COPYSTR function to remove the file extension then you can get the sheetname.
:thumbsup: psycholesterolThinking, programming, coding, developing == Music!0 -
Thanks a lot for help.0
-
My file is a .txt file but the values are separated by ;
If I open it with Excel I get the choice for a separator symbol and then it splits up in columns.
If I use your code I get the complete file in cell A1. Is there a way to set the separator character before opening the file or reading the sheet.CMY0 -
have you tried to (copy and) rename your file?0
-
No I did not rename the file.
The case is solved so thank you for your time.
I'm going to post my solution.CMY0
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