on 09-12-2008 2:53 PM
Hi,
I am going to read a Excel Sheet and import the data in Sales Order?
Any code sample out there?
Thank you,
Rune
Hi Rune,
i have a c# sample here that shows you how to open the excel and access a given cell.
Short description:
- i open a file named Import.xls
- usually you don't need to change the other parameters in the Workbooks.Open
- what you have to do is to add Excel Library and/or Office Libary to your references.
- the logic down shows you how to access a single cell, put the code in a loop
Excel.Application excelApp = new Excel.ApplicationClass();
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(System.IO.Directory.GetParent(System.Windows.Forms.Application.ExecutablePath).ToString() + "\\Import.xls", 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelWorkbook.Worksheets[1];
Excel.Range excelCell = null;
int CellCounter = 1;
string Result = "";
// Get Cell A1
excelCell = (Excel.Range)excelWorksheet.get_Range("A" + CellCounter.ToString(), "A" + CellCounter.ToString());
if (excelCell.Value2.ToString() != null)
{
Result = excelCell.Value2.ToString();
}
CellCounter++;
// Get Cell B1
excelCell = (Excel.Range)excelWorksheet.get_Range("B" + CellCounter.ToString(), "B" + CellCounter.ToString());
if (excelCell.Value2.ToString() != null)
{
Result = excelCell.Value2.ToString();
}
try the code once with a normal excel.
i hope it helps you
lg David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rune,
Unfortunately I don't have any examples available to me at the moment - but would it be possible to use DTW for this purpose? If you were to reformat the excel sheet to fit the template of DTW you wouldn't have to write any further implementation for this as DTW is designed to do it automatically.
[http://service.sap.com/smb/sbo/dtw|http://service.sap.com/smb/sbo/dtw]
However, if you have already looked into this and decided against it, hopefully one of my fellow posters has a few examples.
Regards,
Niall
SAP Business One
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.