当前位置: 首页>>代码示例>>C#>>正文


C# Packaging.WorkbookPart类代码示例

本文整理汇总了C#中DocumentFormat.OpenXml.Packaging.WorkbookPart的典型用法代码示例。如果您正苦于以下问题:C# WorkbookPart类的具体用法?C# WorkbookPart怎么用?C# WorkbookPart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WorkbookPart类属于DocumentFormat.OpenXml.Packaging命名空间,在下文中一共展示了WorkbookPart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertWorksheet

        // Given a WorkbookPart, inserts a new worksheet.
        private static WorksheetPart InsertWorksheet(WorkbookPart workbookPart)
        {
            // Add a new worksheet part to the workbook.
            WorksheetPart newWorksheetPart = workbookPart.AddNewPart<WorksheetPart>();
            newWorksheetPart.Worksheet = new Worksheet(new SheetData());
            newWorksheetPart.Worksheet.Save();

            Sheets sheets = workbookPart.Workbook.GetFirstChild<Sheets>();
            string relationshipId = workbookPart.GetIdOfPart(newWorksheetPart);

            // Get a unique ID for the new sheet.
            uint sheetId = 1;
            if (sheets.Elements<Sheet>().Count() > 0)
            {
                sheetId = sheets.Elements<Sheet>().Select(s => s.SheetId.Value).Max() + 1;
            }

            string sheetName = "Sheet" + sheetId;

            // Append the new worksheet and associate it with the workbook.
            Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
            sheets.Append(sheet);
            workbookPart.Workbook.Save();

            return newWorksheetPart;
        }
开发者ID:assadvirgo,项目名称:Aspose_Cells_NET,代码行数:27,代码来源:Program.cs

示例2: ExcelStreamReader

 private ExcelStreamReader(string fileName)
 {
     this.fileName = fileName;
     this.doc = SpreadsheetDocument.Open(fileName, false);
     this.workbookPart = doc.WorkbookPart;
     this.sheets = GetSheets();
 }
开发者ID:PeterHenell,项目名称:OpenXMLExcelStreamReader,代码行数:7,代码来源:ExcelStreamReader.cs

示例3: GetCellValue

        public static string GetCellValue(WorkbookPart wbPart, Cell theCell)
        {
            string value = theCell.InnerText;
            if (theCell.DataType != null)
            {
                switch (theCell.DataType.Value)
                {
                    case CellValues.SharedString:
                        var stringTable = wbPart.
                          GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
                        if (stringTable != null)
                        {
                            value = stringTable.SharedStringTable.
                              ElementAt(int.Parse(value)).InnerText;
                        }
                        break;

                    case CellValues.Boolean:
                        switch (value)
                        {
                            case "0":
                                value = "FALSE";
                                break;
                            default:
                                value = "TRUE";
                                break;
                        }
                        break;
                }
            }
            return value;
        }
开发者ID:haozhouxu,项目名称:WorkVS2015,代码行数:32,代码来源:Helper.cs

示例4: OpenXLRow

 public OpenXLRow(WorkbookPart wbPart, WorksheetPart wsPart, List<string> columns, Row xRow)
 {
     this.WbPart = wbPart;
     this.WsPart = wsPart;
     this.Columns = columns;
     this._cells = GetCells(xRow);
 }
开发者ID:sympletech,项目名称:SympleLib,代码行数:7,代码来源:OpenXLRow.cs

示例5: FindSheet

 public static Sheet FindSheet(string sheetName, WorkbookPart workbookPart)
 {
     if (string.IsNullOrEmpty(sheetName))
     {
         return workbookPart.Workbook.Descendants<Sheet>().FirstOrDefault();
     }
     return workbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == sheetName).SingleOrDefault<Sheet>();
 }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:8,代码来源:ExcelUtility.cs

示例6: ExcellWorker

 /// <summary>
 /// Создает экземпляр класса для работы с текущим файлом
 /// </summary>
 /// <param name="filePath">Путь к документу</param>
 /// <param name="removeAfterDestroy">Удалять ли файл после окончания работы с ним</param>
 public ExcellWorker(string filePath, bool removeAfterDestroy)
 {
     _currentFilePath = filePath;
     _currentDocument = SpreadsheetDocument.Open(filePath, true);
     _currentWorkBookPart = _currentDocument.WorkbookPart;
     _currentSheet = _currentWorkBookPart.Workbook.Descendants<Sheet>().FirstOrDefault();
     RemoveAfterDestroy = removeAfterDestroy;
 }
开发者ID:gerasyana,项目名称:Academy,代码行数:13,代码来源:ExcellWorker.cs

示例7: GetValueCell

 public string GetValueCell(ref WorkbookPart wbPart, ref WorksheetPart wsPart, string addressName)
 {
     string value = null;
     Cell theCell = wsPart.Worksheet.Descendants<Cell>().
         Where(c => c.CellReference == addressName).FirstOrDefault();
     value = GetCleanValueCell(theCell, ref wbPart);
     return value;
 }
开发者ID:essggarhe4,项目名称:VanickSalesWSTool,代码行数:8,代码来源:ReadExcelOpenXML.cs

示例8: GetSharedStringValue

 public static SharedStringItem GetSharedStringValue(WorkbookPart workbookPart, Cell cell, ref int id)
 {
     if (int.TryParse(cell.InnerText, out id))
     {
         var text = workbookPart.SharedStringTablePart.SharedStringTable.Elements<SharedStringItem>().ElementAt(id);
         return text;
     }
     return null;
 }
开发者ID:monstersatish,项目名称:excel,代码行数:9,代码来源:HomeController.cs

示例9: GetWorksheetFromSheetName

 public static WorksheetPart GetWorksheetFromSheetName(WorkbookPart workbookPart, string sheetName)
 {
     var sheet = workbookPart.Workbook.Descendants<Sheet>().FirstOrDefault(s => s.Name == sheetName);
     if (sheet == null)
     {
         return null;
     }
     return workbookPart.GetPartById(sheet.Id) as WorksheetPart;
 }
开发者ID:dknipper,项目名称:ExcelDocumentProcessor,代码行数:9,代码来源:Processor.cs

示例10: AddCellUnit

        static bool AddCellUnit(int columnIndex, ref int exportColumnIndex, SheetConfig Sheetcfg, Cell cell, WorkbookPart workbookPart, List<string> stylesList, List<CellUnit> cellUnitList)
        {
            if (columnIndex >= Sheetcfg.ColumnConfigData.Count)
                goto Error;

            var columnConfig = Sheetcfg.ColumnConfigData[columnIndex];
            if (!columnConfig.Export)
                return true;

            var dataType = columnConfig.FieldType;
            string cellValue = cell == null ? "" : GetCellValue(cell, workbookPart, stylesList);
            CellUnit cellUnit = null;
            switch (dataType)
            {
                case DesignerDataType.Int:
                    {
                        int intValue = 0;
                        if (!int.TryParse(cellValue, out intValue) && !string.IsNullOrEmpty(cellValue))
                            goto Error;
                        cellUnit = new CellUnitIntValue(exportColumnIndex, intValue);
                    }
                    break;
                case DesignerDataType.Float:
                    {
                        float floatValue = 0.0f;
                        if (!float.TryParse(cellValue, out floatValue) && !string.IsNullOrEmpty(cellValue))
                            goto Error;
                        cellUnit = new CellUnitFloatValue(exportColumnIndex, floatValue);
                    }
                    break;
                case DesignerDataType.String:
                    {
                        cellUnit = new CellUnitStringValue(exportColumnIndex, cellValue);
                    }
                    break;
                case DesignerDataType.Bool:
                    {
                        decimal decimalValue = 0;
                        cellUnit = new CellUnitBoolValue(exportColumnIndex, decimal.TryParse(cellValue, out decimalValue) && decimalValue != 0);
                    }
                    break;
            }

            if (cellUnit.IsNeedWrite())
                cellUnitList.Add(cellUnit);
            ++exportColumnIndex;

            return true;

            Error:
            string excelFileName = "";
            if (!dicOutputFileName.TryGetValue(Sheetcfg.Name, out excelFileName))
                excelFileName = "";
            Console.Error.WriteLine(string.Format(Resources.ExcelConfigFileInValid, excelFileName, Sheetcfg.Name));
            return false;
        }
开发者ID:tyrant39001,项目名称:Tyrant,代码行数:56,代码来源:Program.cs

示例11: Create

 public ExcelHelper Create(string ExcelFile)
 {
     System.IO.FileInfo fi = new System.IO.FileInfo(ExcelFile);
     if (!fi.Directory.Exists)
         fi.Directory.Create();
     _doc = SpreadsheetDocument.Create(ExcelFile, SpreadsheetDocumentType.Workbook);
     _wbPart = _doc.AddWorkbookPart();
     _wbPart.Workbook = new Workbook();
     _doc.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
     return _instance;
 }
开发者ID:Jason-Brody,项目名称:Young,代码行数:11,代码来源:ExcelHelper.cs

示例12: GetCellValue

        protected string GetCellValue(WorkbookPart wbPart, Cell theCell)
        {
            if (theCell == null)
            {
                return null;
            }

            var value = theCell.InnerText;
            if (theCell.DataType == null)
            {
                return value;
            }

            switch (theCell.DataType.Value)
            {
                case (CellValues.SharedString):
                {
                    var stringTable = wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
                    if (stringTable != null)
                    {
                        value = stringTable.SharedStringTable.ElementAt(int.Parse(value)).InnerText;
                    }
                    break;
                }
                case (CellValues.Boolean):
                {
                    switch (value)
                    {
                        case "0":
                        {
                            value = "FALSE";
                            break;
                        }
                        default:
                        {
                            value = "TRUE";
                            break;
                        }
                    }
                    break;
                }
                case (CellValues.Date):
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        value = DateTime.FromOADate(Convert.ToDouble(value)).ToString(CultureInfo.CurrentCulture);
                    }
                    break;
                }
            }

            return value;
        }
开发者ID:dknipper,项目名称:ExcelDocumentProcessor,代码行数:53,代码来源:Processor.cs

示例13: GenerateWorkbookPart1Content

        // Generates content of workbookPart1. 
        private static void GenerateWorkbookPart1Content(WorkbookPart workbookPart1)
        {
            Workbook workbook1 = new Workbook();
            workbook1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");

            Sheets sheets1 = new Sheets();
            Sheet sheet1 = new Sheet() { Name = "Sheet1", SheetId = (UInt32Value)1U, Id = "rId1" };
            sheets1.Append(sheet1);

            workbook1.Append(sheets1);
            workbookPart1.Workbook = workbook1;
        }
开发者ID:aureliopires,项目名称:gisa,代码行数:13,代码来源:XLSXExportHelper.cs

示例14: RetrieveFirstObject

        public List<RPCFan> RetrieveFirstObject(WorkbookPart wbPart, Sheet theSheet)
        {
            string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            WorksheetPart wsPart =
                (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
            Cell theCell = wsPart.Worksheet.Descendants<Cell>().
              Where(c => c != null).FirstOrDefault();
            string first = FindCellInnerValue(wbPart, theCell);
            var letra = first.Substring(0, 1);
            int numeros = int.Parse(first.Substring(1));
            int i = abc.IndexOf(letra);
            List<RPCFan> retorno = new List<RPCFan>();
            int countFans = 0;
            int numeroscopy = numeros;
            while (theCell != null)
            {
                string newRef = abc[i].ToString() + (numeroscopy++ + 1).ToString();
                theCell = wsPart.Worksheet.Descendants<Cell>().
              Where(c => c.CellReference == newRef).FirstOrDefault();
                countFans++;
            }
            for (int ii = 0; ii < (countFans - 1); ii++)
            {
                string newRef;
                i = abc.IndexOf(letra);
                theCell = new Cell();
                var fan = new RPCFan();
                List<string> data = new List<string>();
                while (theCell != null)
                {
                    newRef = abc[i++].ToString() + (numeros + 1).ToString();
                    theCell = wsPart.Worksheet.Descendants<Cell>().
                  Where(c => c.CellReference == newRef).FirstOrDefault();
                    var value = FindCellInnerValue(wbPart, theCell, false);
                    data.Add(value);
                    //i++;
                }
                fan.YaEntro = false;
                fan.LastCell = abc[i-2].ToString() + (numeros + 1).ToString();
                fan.ID = data[0];
                fan.Nombre = data[1];
                fan.CardNum = data[2];
                fan.DNI = data[3];
                fan.Ingreso = data[4];
                if (data[5]!="0")
                    fan.YaEntro = true;

                retorno.Add(fan);
                numeros++;
            }

            return retorno;
        }
开发者ID:CokeAndCode,项目名称:IngresoRPC,代码行数:53,代码来源:RPCHelper.cs

示例15: ReadExcelCell

		private string ReadExcelCell(Cell cell, WorkbookPart workbookPart)
		{
			var cellValue = cell.CellValue;
			var text = (cellValue == null) ? cell.InnerText : cellValue.Text;
			if ((cell.DataType != null) && (cell.DataType == CellValues.SharedString))
			{
				text = workbookPart.SharedStringTablePart.SharedStringTable
					.Elements<SharedStringItem>().ElementAt(
						Convert.ToInt32(cell.CellValue.Text)).InnerText;
			}

			return (text ?? string.Empty).Trim();
		}
开发者ID:slaq777,项目名称:lmsystem,代码行数:13,代码来源:SLExcelReader.cs


注:本文中的DocumentFormat.OpenXml.Packaging.WorkbookPart类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。