예제 #1
0
        /// <summary>
        /// 解析文档
        /// </summary>
        /// <param name="sheet">导出文档</param>
        /// <returns></returns>
        private static ExportingDocument ParseDocument(ISheet sheet)
        {
            var document = new ExportingDocument();

            for (var r = 0; r <= sheet.LastRowNum; r++)
            {
                var row = sheet.GetRow(r);
                if (row == null)
                {
                    break;
                }

                SheetDataSet set = null;

                for (var c = 0; c < row.LastCellNum; c++)
                {
                    var cell = row.GetCell(c);
                    if (cell == null)
                    {
                        break;
                    }

                    if (cell.CellType == CellType.String && !string.IsNullOrEmpty(cell.StringCellValue))
                    {
                        var text = cell.StringCellValue;
                        var si   = text.IndexOf('[');
                        var ei   = text.IndexOf(']', si + 1);
                        if (si != -1 && ei != -1)
                        {
                            set = ParseDataSet(cell, set, text.Substring(si, ei - si + 1), text, r);
                        }
                        else if (text.IndexOf("`") != -1)
                        {
                            document.Formulas.Add(ParseFormula(cell, text));
                        }
                        else if (text == "{Extend}")
                        {
                            document.Extend = cell;
                        }
                    }
                }

                if (set != null)
                {
                    document.DataSets.Add(set);
                }
            }

            return(document);
        }
예제 #2
0
        /// <summary>
        /// 解析数据集
        /// </summary>
        /// <param name="cell">Cell</param>
        /// <param name="set">Set</param>
        /// <param name="key">Text</param>
        /// <param name="format">格式。</param>
        /// <param name="r">起始行索引</param>
        /// <returns></returns>
        private static SheetDataSet ParseDataSet(ICell cell, SheetDataSet set, string key, string format, int r)
        {
            if (set == null)
            {
                set = new SheetDataSet();
                set.StartRowIndex = r;
            }

            if (format == key)
            {
                format = string.Empty;
            }

            var ditem = new CellDataMap(key.Substring(1, key.Length - 2), format);

            set.Properties.Add(cell, ditem);

            return(set);
        }