예제 #1
0
 void RenderSheet(ExcelSheetMetaData meta, ISheet sheet, JToken json)
 {
     foreach (var cellTemplate in meta.CellTemplates)
     {
         cellTemplate.SetValue(sheet, json);
     }
     foreach (var tableTemplate in meta.TableTemplates)
     {
         tableTemplate.SetValue(sheet, json);
     }
 }
예제 #2
0
        ExcelSheetMetaData ParseSheet(ISheet sheet)
        {
            ExcelSheetMetaData sheetMeta = new ExcelSheetMetaData();

            sheetMeta.SheetName = sheet.SheetName;

            foreach (IRow row in sheet)
            {
                ParseRow(row, sheetMeta);
            }
            return(sheetMeta);
        }
예제 #3
0
        public ExcelMetaData Parse(IWorkbook workbook)
        {
            var meta = new ExcelMetaData();

            meta.Workbook = workbook;
            for (int i = 0; i < workbook.NumberOfSheets; i++)
            {
                ISheet             sheet     = workbook.GetSheetAt(i);
                ExcelSheetMetaData sheetMeta = ParseSheet(sheet);
                sheetMeta.SheetIndex = i;
                meta.Sheets.Add(sheetMeta);
            }
            return(meta);
        }
예제 #4
0
        void ParseTable(ICell cell, string template, ExcelSheetMetaData sheetMeta)
        {
            var        tokens        = template.Split(',');
            ExcelTable tableTemplate = new ExcelTable()
            {
                RowIndex = cell.RowIndex,
                ColIndex = cell.ColumnIndex,
            };


            foreach (var token in tokens)
            {
                var pair = token.Split(':');

                switch (pair[0].ToLower())
                {
                case "each":
                    tableTemplate.Each = pair[1];
                    break;

                case "direction":
                    tableTemplate.Direction = pair[1];
                    break;

                case "treecode":
                    tableTemplate.TreeCode = pair[1];
                    break;
                }
            }

            var row = cell.Row;

            for (int i = cell.ColumnIndex; i < row.LastCellNum; i++)
            {
                ParseCell(row.Cells[i], tableTemplate.Cells);
            }
            if (tableTemplate.Cells.FirstOrDefault(o => o.IsHide || o.IsLock) != null)
            {
                cell.Sheet.ProtectSheet(PROTECT_PASSWROD);
            }

            sheetMeta.TableTemplates.Add(tableTemplate);
        }
예제 #5
0
        void ParseRow(IRow row, ExcelSheetMetaData sheetMeta)
        {
            foreach (ICell cell in row)
            {
                var template = GetTemplate(cell);
                if (string.IsNullOrEmpty(template))
                {
                    continue;
                }

                if (template.IndexOf("each:") > -1)
                {
                    ParseTable(cell, template, sheetMeta);
                    return;
                }
                else
                {
                    ParseCell(cell, sheetMeta.CellTemplates);
                }
            }
        }
예제 #6
0
        void ParseTable(ICell cell, string template, ExcelSheetMetaData sheetMeta)
        {
            var tokens = template.Split(',');
            ExcelTable tableTemplate = new ExcelTable()
            {
                RowIndex = cell.RowIndex,
                ColIndex = cell.ColumnIndex,

            };

            foreach (var token in tokens)
            {
                var pair = token.Split(':');

                switch (pair[0].ToLower())
                {
                    case "each":
                        tableTemplate.Each = pair[1];
                        break;
                    case "direction":
                        tableTemplate.Direction = pair[1];
                        break;
                    case "treecode":
                        tableTemplate.TreeCode = pair[1];
                        break;
                }

            }

            var row = cell.Row;
            for (int i = cell.ColumnIndex; i < row.LastCellNum; i++)
            {
                ParseCell(row.Cells[i], tableTemplate.Cells);
            }
            if (tableTemplate.Cells.FirstOrDefault(o => o.IsHide || o.IsLock) != null)
            {
                cell.Sheet.ProtectSheet(PROTECT_PASSWROD);
            }

            sheetMeta.TableTemplates.Add(tableTemplate);
        }
예제 #7
0
        ExcelSheetMetaData ParseSheet(ISheet sheet)
        {
            ExcelSheetMetaData sheetMeta = new ExcelSheetMetaData();
            sheetMeta.SheetName = sheet.SheetName;

            foreach (IRow row in sheet)
            {
                ParseRow(row, sheetMeta);
            }
            return sheetMeta;
        }
예제 #8
0
        void ParseRow(IRow row, ExcelSheetMetaData sheetMeta)
        {
            foreach (ICell cell in row)
            {
                var template = GetTemplate(cell);
                if (string.IsNullOrEmpty(template))
                    continue;

                if (template.IndexOf("each:") > -1)
                {
                    ParseTable(cell, template, sheetMeta);
                    return;
                }
                else
                {
                    ParseCell(cell, sheetMeta.CellTemplates);
                }

            }
        }
예제 #9
0
        void RenderSheet(ExcelSheetMetaData meta, ISheet sheet, JToken json)
        {
            foreach (var cellTemplate in meta.CellTemplates)
            {
                cellTemplate.SetValue(sheet, json);

            }
            foreach (var tableTemplate in meta.TableTemplates)
            {

                tableTemplate.SetValue(sheet, json);
            }
        }