public XWorksheet(XDimention xd) : this() { int rowCount = xd.RowCount; int columnCount = xd.ColumnCount; // перенести в XWorksheet OutlinePropertiesTable.Columns.Add("", typeof(int)); for (int i = 0; i < columnCount; i++) { CellValuesTable.Columns.Add("", typeof(object)); } for (int i = 0; i < rowCount; i++) { OutlinePropertiesTable.Rows.Add(OutlinePropertiesTable.NewRow()); CellValuesTable.Rows.Add(CellValuesTable.NewRow()); } }
public void LoadXlsx(string path) { // Буфер - чтобы не держать файл открытым. MemoryStream memoryStream = new MemoryStream(); using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read)) { stream.CopyTo(memoryStream); } using (SpreadsheetDocument package = SpreadsheetDocument.Open(memoryStream, false)) { WorkbookPart workbookPart = package.WorkbookPart; SharedStringTablePart sharedStringTablePart = workbookPart.SharedStringTablePart; this.sharedStringTable = sharedStringTablePart.SharedStringTable; WorkbookStylesPart workbookStylesPart = workbookPart.WorkbookStylesPart; this.stylesheet = workbookStylesPart.Stylesheet; Workbook workbook = workbookPart.Workbook; Sheets sheets = workbook.Sheets; foreach (Sheet sheet in sheets.Descendants <Sheet>()) { WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id); Worksheet worksheet = worksheetPart.Worksheet; // размеры XDimention xd = new XDimention(worksheet.SheetDimension.Reference); // добавляем новый лист в представление Net XWorksheet xWorksheet = new XWorksheet(xd); XWorksheets.Add(xWorksheet); xWorksheet.Name = sheet.Name; // разбор свойств листа parseSheetProperties(worksheet, xWorksheet); // разбор данных parseSheetData(worksheet, xWorksheet); // разбор объединений ячеек parseMegreCells(worksheet, xWorksheet); } } memoryStream.Dispose(); }