Beispiel #1
0
        private static WorksheetNode BuildWorkSheet(string name, DataView view, DataViewExportOptions options)
        {
            WorksheetNode worksheet = new WorksheetNode();

            worksheet.Name = name;

            FillIntoWorksheet(worksheet, view, options);

            return(worksheet);
        }
Beispiel #2
0
        private static void FillIntoWorksheet(WorksheetNode worksheet, DataView view, DataViewExportOptions options)
        {
            foreach (DataColumn column in view.Table.Columns)
            {
                if (options.IgnoredColumnNames.Exists(c => c == column.ColumnName) == false)
                {
                    ColumnNode columnNode = new ColumnNode();

                    columnNode.Caption = column.ColumnName;

                    options.OnDateViewExportColumnHeader(column, columnNode, options.Context);

                    worksheet.Table.Columns.Add(columnNode);
                }
            }

            bool isFirstRow = true;

            if (options.ExportColumnHeader)
            {
                RowNode rowNode = BuildHeaderRow(view.Table.Columns);

                if (options.StartRow > 0)
                {
                    rowNode.Index = options.StartRow;
                }

                worksheet.Table.Rows.Add(rowNode);

                isFirstRow = false;
            }

            foreach (DataRowView drv in view)
            {
                RowNode rowNode = new RowNode();

                if (isFirstRow)
                {
                    if (options.StartRow > 0)
                    {
                        rowNode.Index = options.StartRow;
                    }

                    isFirstRow = false;
                }

                bool isFirstColumn = true;

                foreach (DataColumn column in view.Table.Columns)
                {
                    if (options.IgnoredColumnNames.Exists(c => c == column.ColumnName) == false)
                    {
                        CellNode cellNode = new CellNode();

                        cellNode.Data.Type = GetCellDataType(column);
                        object dataValue = drv[column.ColumnName];

                        if (dataValue != null)
                        {
                            if (cellNode.Data.Type == CellDataType.DateTime && (dataValue is DateTime))
                            {
                                cellNode.Data.Value = string.Format("{0:yyyy-MM-ddTHH:mm:ss}", dataValue);
                                cellNode.StyleID    = "NormalDateTime";
                            }
                            else
                            {
                                cellNode.Data.Value = dataValue.ToString();
                            }
                        }

                        if (isFirstColumn)
                        {
                            if (options.StartColumn > 0)
                            {
                                cellNode.Index = options.StartColumn;
                            }

                            isFirstColumn = false;
                        }

                        options.OnDateViewExportColumnData(column, cellNode, dataValue, options.Context);

                        rowNode.Cells.Add(cellNode);
                    }
                }

                worksheet.Table.Rows.Add(rowNode);
            }
        }
Beispiel #3
0
        public static void FillIntoSpreadSheet(this DataView view, WorkbookNode workbook, string worksheetName, DataViewExportOptions options)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(view != null, "view");
            ExceptionHelper.FalseThrow <ArgumentNullException>(workbook != null, "workbook");
            ExceptionHelper.CheckStringIsNullOrEmpty(worksheetName, "worksheetName");
            ExceptionHelper.FalseThrow <ArgumentNullException>(options != null, "options");

            InitStyles(workbook);

            ExceptionHelper.FalseThrow(workbook.Worksheets.Contains(worksheetName), "不能找到名称为{0}的Worksheet", worksheetName);

            WorksheetNode worksheet = workbook.Worksheets[worksheetName];

            FillIntoWorksheet(worksheet, view, options);
        }
Beispiel #4
0
        public static void FillIntoSpreadSheet(this DataView view, WorkbookNode workbook, string worksheetName)
        {
            DataViewExportOptions options = new DataViewExportOptions();

            FillIntoSpreadSheet(view, workbook, worksheetName, options);
        }
Beispiel #5
0
        public static WorkbookNode ExportToSpreadSheet(this DataView view, string worksheetName, DataViewExportOptions options)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(view != null, "view");
            ExceptionHelper.CheckStringIsNullOrEmpty(worksheetName, "worksheetName");
            ExceptionHelper.FalseThrow <ArgumentNullException>(options != null, "options");

            WorkbookNode workbook = new WorkbookNode();

            InitStyles(workbook);
            workbook.Worksheets.Add(BuildWorkSheet(worksheetName, view, options));

            return(workbook);
        }
Beispiel #6
0
        public static WorkbookNode ExportToSpreadSheet(this DataView view, string worksheetName)
        {
            DataViewExportOptions options = new DataViewExportOptions();

            return(ExportToSpreadSheet(view, worksheetName, options));
        }