コード例 #1
0
 public ExcelSheet(Sheet sheet, ExcelDocument doc)
 {
     this.sheet     = sheet;
     this.document  = doc;
     this.worksheet = ((WorksheetPart)(doc.document.WorkbookPart.GetPartById(sheet.Id))).Worksheet;
     _rows          = new ExcelRowCollection(this);
 }
コード例 #2
0
 public ExcelSheetCollection(ExcelDocument doc)
 {
     this.document = doc;
     this.List     = new SortedDictionary <uint, ExcelSheet>();
     foreach (Sheet sheet in doc.document.WorkbookPart.Workbook.Descendants <Sheet>())
     {
         this.List.Add(sheet.SheetId, new ExcelSheet(sheet, doc));
     }
 }
コード例 #3
0
        public ExcelSheet(ExcelDocument doc, string name)
        {
            this.document = doc;
            WorksheetPart newWorksheetPart = doc.document.WorkbookPart.AddNewPart <WorksheetPart>();

            worksheet = new Worksheet(new SheetData());
            newWorksheetPart.Worksheet = worksheet;

            Sheets sheets = doc.document.WorkbookPart.Workbook.GetFirstChild <Sheets>();

            if (sheets == null)
            {
                sheets = doc.document.WorkbookPart.Workbook.AppendChild <Sheets>(new Sheets());
            }

            string relationshipId = doc.document.WorkbookPart.GetIdOfPart(newWorksheetPart);
            // Get a unique ID for the new worksheet.
            uint sheetId = 1;

            if (sheets.Elements <Sheet>().Count() > 0)
            {
                sheetId = sheets.Elements <Sheet>().Select(s => s.SheetId.Value).Max() + 1;
            }

            // Give the new worksheet a name.
            string sheetName = "Sheet";

            if (String.IsNullOrEmpty(name))
            {
                sheetName = getSheetName(sheetName, sheets.Elements <Sheet>(), 1);
            }
            else
            {
                sheetName = getSheetName(name, sheets.Elements <Sheet>());
            }
            // Append the new worksheet and associate it with the workbook.
            sheet = new Sheet()
            {
                Id = relationshipId, SheetId = sheetId, Name = sheetName
            };
            sheets.Append(sheet);

            _rows = new ExcelRowCollection(this);
        }
コード例 #4
0
ファイル: OpenXmlExcel.cs プロジェクト: siwigor/OpenXmlExcel
 public ExcelSheetCollection(ExcelDocument doc)
 {
     this.document = doc;
     this.List = new SortedDictionary<uint, ExcelSheet>();
     foreach (Sheet sheet in doc.document.WorkbookPart.Workbook.Descendants<Sheet>())
         this.List.Add(sheet.SheetId, new ExcelSheet(sheet, doc));
 }
コード例 #5
0
ファイル: OpenXmlExcel.cs プロジェクト: siwigor/OpenXmlExcel
 public ExcelSheet(Sheet sheet, ExcelDocument doc)
 {
     this.sheet = sheet;
     this.document = doc;
     this.worksheet = ((WorksheetPart)(doc.document.WorkbookPart.GetPartById(sheet.Id))).Worksheet;
     _rows = new ExcelRowCollection(this);
 }
コード例 #6
0
ファイル: OpenXmlExcel.cs プロジェクト: siwigor/OpenXmlExcel
        public ExcelSheet(ExcelDocument doc, string name)
        {
            this.document = doc;
            WorksheetPart newWorksheetPart = doc.document.WorkbookPart.AddNewPart<WorksheetPart>();
            worksheet = new Worksheet(new SheetData());
            newWorksheetPart.Worksheet = worksheet;

            Sheets sheets = doc.document.WorkbookPart.Workbook.GetFirstChild<Sheets>();
            if (sheets == null)
                sheets = doc.document.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());

            string relationshipId = doc.document.WorkbookPart.GetIdOfPart(newWorksheetPart);
            // Get a unique ID for the new worksheet.
            uint sheetId = 1;
            if (sheets.Elements<Sheet>().Count() > 0)
                sheetId = sheets.Elements<Sheet>().Select(s => s.SheetId.Value).Max() + 1;

            // Give the new worksheet a name.
            string sheetName = "Sheet";
            if (String.IsNullOrEmpty(name))
                sheetName = getSheetName(sheetName, sheets.Elements<Sheet>(), 1);
            else
                sheetName = getSheetName(name, sheets.Elements<Sheet>());
            // Append the new worksheet and associate it with the workbook.
            sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
            sheets.Append(sheet);

            _rows = new ExcelRowCollection(this);
        }