コード例 #1
0
/*
 *      static Excel.SharedStringTable SaveSharedStringTable()
 *      {
 *          var exportedSharedStringTable = new Excel.SharedStringTable();
 *
 *          return exportedSharedStringTable;
 *      }
 */

        static void SaveSheet(Package.WorkbookPart exportedWorkbookPart, Excel.Stylesheet styleSheet, Dictionary <CellFormat, uint> cellFormatList, Excel.Sheets exportedSheets, Sheet sheet, uint sheetId)
        {
            var    exportedWorksheetPart = exportedWorkbookPart.AddNewPart <Package.WorksheetPart>();
            string relId = exportedWorkbookPart.GetIdOfPart(exportedWorksheetPart);

            var exportedWorksheet = new Excel.Worksheet();

            exportedWorksheetPart.Worksheet = exportedWorksheet;

            var exportedColumns = new Excel.Columns();

            exportedWorksheet.Append(exportedColumns);

            var exportedSheetData = new Excel.SheetData();

            exportedWorksheet.Append(exportedSheetData);

            var exportedSheet = new Excel.Sheet()
            {
                Name = sheet.Name, Id = relId, SheetId = sheetId
            };

            if (sheet.Hidden)
            {
                exportedSheet.State = Excel.SheetStateValues.Hidden;
            }
            exportedSheets.Append(exportedSheet);

            foreach (var column in sheet.Columns.OrderBy(r => r.Index))
            {
                SaveColumn(exportedColumns, column);
            }

            foreach (var row in sheet.Rows.OrderBy(r => r.Index))
            {
                SaveRow(exportedSheetData, styleSheet, cellFormatList, row);
            }

            exportedWorksheetPart.Worksheet.Save();
        }
コード例 #2
0
        public static xdr.WorksheetDrawing GetWorksheetDrawing(this x.Worksheet ws)
        {
            var drawingsPart = ws.WorksheetPart.GetPartsOfType <DrawingsPart>().FirstOrDefault();

            if (drawingsPart == null)
            {
                var count = ws.WorksheetPart.Parts.Count();
                drawingsPart = ws.WorksheetPart.AddNewPart <DrawingsPart>("rId" + (count + 1));
            }
            var drawingsPartId   = ws.WorksheetPart.GetIdOfPart(drawingsPart);
            var worksheetDrawing = drawingsPart.WorksheetDrawing;

            if (worksheetDrawing == null)
            {
                worksheetDrawing = new xdr.WorksheetDrawing();
                worksheetDrawing.AddNamespaceDeclaration("xdr", "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
                worksheetDrawing.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
                drawingsPart.WorksheetDrawing = worksheetDrawing;
            }
            var drawing = ws.GetFirstChild <x.Drawing>();

            if (drawing == null)
            {
                drawing = new x.Drawing()
                {
                    Id = drawingsPartId
                };
                ws.Append(drawing);
            }

            var wbPart = ws.WorksheetPart.ParentPartOfType <WorkbookPart>();

            wbPart.Workbook.Save();

            return(worksheetDrawing);
        }