Ejemplo n.º 1
0
        private ExcelTable ReadSheet(int rowCount, int colCount, DataTable dataTable)
        {
            ExcelTable table = new ExcelTable();
            table.Data = new List<List<string>>();

            for (int row = 0; row < rowCount; ++row)
            {
                var properties = new List<string>();
                for (int col = 0; col < colCount; ++col)
                {
                    var elem = dataTable.Rows[row][col].ToString();
                    if (elem.Equals("##"))
                    {
                        return null;
                    }
                    if(UseAnnotation() && dataTable.Rows[row][0].ToString().StartsWith("#"))
                    {
                        properties.Add(null);
                    }
                    else
                    {
                        properties.Add(elem);
                    }

                }
                table.Data.Add(properties);
            }

            return table;
        }
Ejemplo n.º 2
0
        public override ExcelData ReadExcel(string path)
        {
            var time = DateTime.Now;
            ExcelData res = new ExcelData();
            res.DataList = new List<ExcelTable>();
            string strConn
                = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source="
                + path
                + ";Extended Properties='Excel 12.0; HDR=NO; IMEX=1'";

            var sheets = GetExcelSheetName(strConn);
            foreach (var sheetName in sheets)
            {
                ExcelTable tmpTable = new ExcelTable();
                tmpTable.Data = ReadSheet(strConn, sheetName);
                res.DataList.Add(tmpTable);
            }
            var space = DateTime.Now - time;
            Console.WriteLine("cost time " + space.TotalMilliseconds);
            LogQueue.Instance.Enqueue("DB reader cost time " + space.TotalMilliseconds);
            return res;
        }