Importando do Excel via código
02
Apr
2008
Posted by: Ricardo Pichler in: X++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| void importFromExcel()
{
myTable myTable;
COMVariant COMVariant1;
SysExcelApplication app;
SysExcelWorkbooks Workbooks;
SysExcelWorkbook Workbook;
SysExcelWorksheets Worksheets;
SysExcelWorksheet Worksheet;
SysExcelCells Cells;
SysExcelCell RCell;
int i;
#excel
app = SysExcelApplication::construct();
Workbooks = app.Workbooks();
COMVariant1 = new COMVariant();
COMVariant1.bStr("C:\\myExcel.xls");
Workbook = Workbooks.Add(COMVariant1);
Worksheets = Workbook.worksheets();
Worksheet = Worksheets.itemFromName("myTable");
Cells = Worksheet.Cells();
i = 2;
RCell = Cells.Item(i, 1);
ttsbegin;
while(RCell.Value().bStr() != '')
{
myTable.Field1Id = RCell.value().bStr();
RCell = Cells.Item(i, 2);
myTable.Field2 = RCell.value().bStr();
RCell = Cells.Item(i, 3);
myTable.FieldInt = str2int(RCell.value().toString());
RCell = Cells.Item(i, 4);
myTable.FieldReal = str2num(RCell.value().toString());
RCell = Cells.Item(i, 5);
myTable.FieldDate = RCell.value().date();
myTable.insert();
i++;
RCell = Cells.Item(i, 1);
}
ttscommit;
} |
void importFromExcel()
{
myTable myTable;
COMVariant COMVariant1;
SysExcelApplication app;
SysExcelWorkbooks Workbooks;
SysExcelWorkbook Workbook;
SysExcelWorksheets Worksheets;
SysExcelWorksheet Worksheet;
SysExcelCells Cells;
SysExcelCell RCell;
int i;
#excel
app = SysExcelApplication::construct();
Workbooks = app.Workbooks();
COMVariant1 = new COMVariant();
COMVariant1.bStr("C:\\myExcel.xls");
Workbook = Workbooks.Add(COMVariant1);
Worksheets = Workbook.worksheets();
Worksheet = Worksheets.itemFromName("myTable");
Cells = Worksheet.Cells();
i = 2;
RCell = Cells.Item(i, 1);
ttsbegin;
while(RCell.Value().bStr() != '')
{
myTable.Field1Id = RCell.value().bStr();
RCell = Cells.Item(i, 2);
myTable.Field2 = RCell.value().bStr();
RCell = Cells.Item(i, 3);
myTable.FieldInt = str2int(RCell.value().toString());
RCell = Cells.Item(i, 4);
myTable.FieldReal = str2num(RCell.value().toString());
RCell = Cells.Item(i, 5);
myTable.FieldDate = RCell.value().date();
myTable.insert();
i++;
RCell = Cells.Item(i, 1);
}
ttscommit;
}
2 Responses
bilderupload
04|Oct|2014 1This is a good tip especially to those new to the blogosphere.
Simple but very accurate info_ Appreciate your sharing this one.
A must read article!
Anonymous
04|Oct|2017 2Obrigado pelo artigo gostei bastante, tirou varias duvidas que tinha.
Muito interessante mesmo! Continue com o bom trabalho!
Leave a reply