• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Packaging.WorkbookPart类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetHeaders

        private static Dictionary<int, string> GetHeaders(SheetData sheetData, WorkbookPart workbookPart)
        {
            var headers = new Dictionary<int, string>();

            var headerCells = sheetData.Elements<Row>().First().Elements<Cell>().ToList();

            for (var i = 0; i < headerCells.Count; i++)
            {
                var cellValue = ExcelFileInceptor.GetCellValueAsString(workbookPart, headerCells[i]);
                headers.Add(i, cellValue);
            }
            return headers;
        }
开发者ID:igiel,项目名称:Etf,代码行数:13,代码来源:ExcelParser.cs


示例17: AddReportColumns

        private void AddReportColumns(WorkbookPart workbookPart, WorksheetPart worksheetPart, List<string> columnNames)
        {
            for (int i = 0; i < columnNames.Count; i++)
            {
                string fieldName = columnNames[i];

                WorkbookHelper.AddCellText(
                    workbookPart,
                    worksheetPart,
                    fieldName,
                    (uint)(i + 1), 1U);
            }
        }
开发者ID:soshimozi,项目名称:Cron-Plugin-Service,代码行数:13,代码来源:ReportGenerator.cs


示例18: LogGenerator

        private WorksheetPart wsSheet = null; //  WorkSheetPart

        #endregion Fields

        #region Constructors

        public LogGenerator(string fn)
        {
            ////  get spreadsheet path from constructor
            //path = folder;
            ////  File name is based on date and time
            //DateTime now = DateTime.Now;
            ////  Construct the spreadsheet filename
            //string fn = string.Format("{0}\\report_{1}-{2}-{3}_{4}{5}{6}.xlsx",
            //    path, now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
            if (File.Exists(fn))
            {
                doc = SpreadsheetDocument.Open(fn, true);
            }
            else
            {
                //
                //  Create the Spreadsheet document
                //
                doc = SpreadsheetDocument.Create(fn, SpreadsheetDocumentType.Workbook);
                //
                //  Add WoorkBookPart to the document
                //
                wbPart = doc.AddWorkbookPart();
                wbPart.Workbook = new Workbook();
                wbPart.Workbook.AddNamespaceDeclaration("x", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
                //
                //  Add WorkSheetPart to the WorkBookPart
                //
                wsSheet = wbPart.AddNewPart<WorksheetPart>();
                wsSheet.Worksheet = new Worksheet(new SheetData());
                wsSheet.Worksheet.AddNamespaceDeclaration("x", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
                //
                //  Add sheets to the WorkBook
                //
                sheets = doc.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());
                //
                //  Append new sheet and associate it with the workbook
                //
                sheet = new Sheet() { Id = doc.WorkbookPart.GetIdOfPart(wsSheet), SheetId = 1, Name = wsName };
                sheet.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
                sheets.Append(sheet);

                wbPart.Workbook.Save();
                //CreatePackage(fn);

                //if (File.Exists(fn))
                //{
                //    TestXls();
                //}
            }
        }
开发者ID:Rossano,项目名称:Dome_Control,代码行数:57,代码来源:LogLib.cs


示例19: GetSheetNames

 /// <summary>
 /// 根据WorkbookPart获取所有SheetName
 /// </summary>
 /// <param name="workBookPart"></param>
 /// <returns>SheetName集合</returns>
 private List<string> GetSheetNames(WorkbookPart workBookPart)
 {
     List<string> sheetNames = new List<string>();
     Sheets sheets = workBookPart.Workbook.Sheets;
     foreach (Sheet sheet in sheets)
     {
         string sheetName = sheet.Name;
         if (!string.IsNullOrEmpty(sheetName))
         {
             sheetNames.Add(sheetName);
         }
     }
     return sheetNames;
 }
开发者ID:bobozhang,项目名称:ExcelImportExportInTemplate,代码行数:19,代码来源:Default2.aspx.cs


示例20: AddReportLines

 private void AddReportLines(WorkbookPart workbookPart, WorksheetPart worksheetPart, Report report, uint startRow)
 {
     for (int iRow = 0; iRow < report.ReportLines.Count; iRow++)
     {
         for (int iCol = 0; iCol < report.ColumnNames.Count; iCol++)
         {
             WorkbookHelper.AddCellText(
                 workbookPart,
                 worksheetPart,
                 report[iRow][iCol].ToString(),
                 (uint)iCol + 1, (uint)iRow + startRow + 1);
         }
     }
 }
开发者ID:soshimozi,项目名称:Cron-Plugin-Service,代码行数:14,代码来源:ReportGenerator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Packaging.WorksheetPart类代码示例发布时间:2022-05-24
下一篇:
C# Packaging.MainDocumentPart类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap