예제 #1
0
        private static void SheetImport(Tk5ListMetaData metaInfos, DataTable dataTable, ISheet sheet,
                                        ResultHolder resultHolder)
        {
            if (sheet != null)
            {
                Dictionary <string, Tk5FieldInfoEx> dicOfInfo = new Dictionary <string, Tk5FieldInfoEx>();
                foreach (Tk5FieldInfoEx info in metaInfos.Table.TableList)
                {
                    dicOfInfo.Add(info.DisplayName, info);
                }

                IRow   headerRow  = sheet.GetRow(0);
                IRow   row        = null;
                string columnName = string.Empty;
                string strValue   = string.Empty;
                ICell  cell       = null;
                for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
                {
                    row = sheet.GetRow(i);
                    DataRow dataRow = dataTable.NewRow();
                    for (int j = headerRow.FirstCellNum; j < headerRow.LastCellNum; j++)
                    {
                        columnName = headerRow.GetCell(j).ToString();
                        cell       = row.GetCell(j);
                        strValue   = ((cell == null) ? string.Empty : cell.ToString());
                        ImportResult imResult = TablePadding(dataRow, columnName, dicOfInfo, strValue, i);
                        if (imResult != null)
                        {
                            resultHolder.Add(imResult);
                        }
                    }
                    dataTable.Rows.Add(dataRow);
                }
            }
        }
예제 #2
0
        public OutputData DoAction(IInputData input)
        {
            NPOIRead.CreateExcelTemplate(fMetaData);

            string       strName = @"D:\ImportTest.xls";
            ResultHolder rh      = new ResultHolder();
            DataSet      dSet    = null;

            try
            {
                dSet = NPOIRead.ExcelImport(strName, fMetaData, rh);
            }
            catch
            {
            }

            return(OutputData.Create(dSet));
        }
예제 #3
0
        public static DataSet ExcelImport(string strFileName, Tk5ListMetaData metaInfos, ResultHolder resultHolder)
        {
            DataSet      dataSet      = new DataSet();
            DataTable    dataTable    = DataSetUtil.CreateDataTable(metaInfos.Table.TableName, metaInfos.Table.TableList);
            string       sheetName    = metaInfos.Table.TableDesc;
            HSSFWorkbook hssfworkbook = null;
            XSSFWorkbook xssfworkbook = null;
            ISheet       sheet        = null;

            string fileExt = Path.GetExtension(strFileName);

            using (FileStream file = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
            {
                if (fileExt == ".xls")
                {
                    hssfworkbook = new HSSFWorkbook(file);
                }
                else if (fileExt == ".xlsx")
                {
                    xssfworkbook = new XSSFWorkbook(file);
                }
            }

            if (hssfworkbook != null)
            {
                sheet = hssfworkbook.GetSheet(sheetName);
            }
            else if (xssfworkbook != null)
            {
                sheet = xssfworkbook.GetSheet(sheetName);
            }

            SheetImport(metaInfos, dataTable, sheet, resultHolder);
            dataSet.Tables.Add(dataTable);
            return(dataSet);
        }