Beispiel #1
0
        public XElement Serialize()
        {
            XElement element = new XElement("parameter");

            element.SetAttributeValue("name", this.SheetName);

            if (this.ObjectSheetRows.Count > 0)
            {
                ObjectSheetRow headerRow = this.ObjectSheetRows[0];

                foreach (ObjectSheetRow objectSheetRow in this.ObjectSheetRows)
                {
                    if (objectSheetRow != headerRow)
                    {
                        element.Add(objectSheetRow.Serialize(headerRow.ObjectSheetRowCells));
                    }
                }
            }

            return(element);
        }
Beispiel #2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            StringBuilder stringBuilder = new StringBuilder();

            ObjectWorkBook objectWorkBook = new ObjectWorkBook();

            using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(txtExcelFromTeam.Text, false))
            {
                foreach (Sheet sheet in spreadsheetDocument.WorkbookPart.Workbook.Sheets.Elements())
                {
                    if (sheet.Name.ToString().Trim().ToUpper() == "CALCULATION")
                    {
                        continue;
                    }

                    ObjectSheet objectSheet = new ObjectSheet();
                    objectSheet.SheetName = sheet.Name;
                    objectWorkBook.ObjectSheets.Add(objectSheet);

                    WorksheetPart worksheetPart = (WorksheetPart)spreadsheetDocument.WorkbookPart.GetPartById(sheet.Id);

                    foreach (SheetData sheetData in worksheetPart.Worksheet.Elements <SheetData>())
                    {
                        foreach (Row r in sheetData.Elements <Row>())
                        {
                            ObjectSheetRow objectSheetRow = new ObjectSheetRow();
                            objectSheet.ObjectSheetRows.Add(objectSheetRow);

                            foreach (Cell c in r.Elements <Cell>())
                            {
                                if (c.InnerText.Length > 0)
                                {
                                    string val = c.InnerText;

                                    if (c.DataType != null)
                                    {
                                        switch (c.DataType.Value)
                                        {
                                        case CellValues.SharedString:

                                            var stringTable = spreadsheetDocument.WorkbookPart.GetPartsOfType <SharedStringTablePart>().FirstOrDefault();

                                            if (stringTable != null)
                                            {
                                                val = stringTable.SharedStringTable.ElementAt(int.Parse(val)).InnerText;
                                            }
                                            break;

                                        case CellValues.Boolean:

                                            switch (val)
                                            {
                                            case "0":
                                                val = "FALSE";
                                                break;

                                            default:
                                                val = "TRUE";
                                                break;
                                            }
                                            break;
                                        }
                                    }

                                    objectSheetRow.ObjectSheetRowCells.Add(val);
                                }
                            }
                        }
                    }
                }
            }

            txtPreview.Text = objectWorkBook.Serialize().ToString();
        }