-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathDEVFileReaderExcel.xml
More file actions
129 lines (111 loc) · 3.16 KB
/
DEVFileReaderExcel.xml
File metadata and controls
129 lines (111 loc) · 3.16 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?xml version="1.0" encoding="utf-8"?>
<AxClass xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Name>DEVFileReaderExcel</Name>
<SourceCode>
<Declaration><![CDATA[
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class DEVFileReaderExcel extends DEVFileReaderBase
{
ExcelWorksheet excelWorksheet;
}
]]></Declaration>
<Methods>
<Method>
<Name>openFile</Name>
<Source><![CDATA[
public void openFile(System.IO.Stream _stream)
{
this.initNewFile();
if (! _stream )
{
return;
}
ExcelPackage package = new ExcelPackage(_stream);
if (! workShetNo)
{
workShetNo = package.Workbook.View.ActiveTab + 1;
}
excelWorksheet = package.Workbook.Worksheets.get_Item(workShetNo ? workShetNo : 1);
if (! excelWorksheet)
{
throw error("Failed to open Excel file");
}
this.readExcelDataToCon();
}
]]></Source>
</Method>
<Method>
<Name>readExcelDataToCon</Name>
<Source><![CDATA[
private void readExcelDataToCon()
{
int i,j;
container rowData;
for (i = 1; i <= excelWorksheet.Dimension.End.Row; i++)
{
rowData = conNull();
for (j = 1; j <= excelWorksheet.Dimension.End.Column; j++)
{
rowData += this.getExcelCellValueInternal(i, j);
}
excelDataCon += [rowData];
rowsCount++;
}
excelWorksheet = null;
}
]]></Source>
</Method>
<Method>
<Name>getExcelCellValueInternal</Name>
<Source><![CDATA[
private anytype getExcelCellValueInternal(int _row, int _column)
{
anytype res ;
str typeName;
OfficeOpenXml.ExcelRange er = excelWorksheet.Cells.get_Item(_row, _column);
var val = er.get_Value();
if (! val)
{
res = '';
}
else
{
System.Type t= val.GetType();
typeName = t.Name;
str typeString;
int64 typeInt;
real typeReal;
utcdatetime typeDateTime;
switch (typeName)
{
case 'String' :
case 'ExcelErrorValue' :
typeString = val.ToString();
res = strLRTrim(typeString);
break;
case 'DateTime' :
typeDateTime = val;
res = typeDateTime;
break;
case 'Int32' :
case 'Int64' :
typeInt = System.Convert::ToInt64(val);
res = typeInt;
break;
case 'Double' :
typeReal = System.Convert::ToDouble(val);
res = typeReal;
break;
default :
throw error(strFmt("Incorrect type %1 in row %2, column %3", typeName, _row, _column));
}
}
return res;
}
]]></Source>
</Method>
</Methods>
</SourceCode>
</AxClass>