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


C# Worksheet.GetFirstChild方法代码示例

本文整理汇总了C#中Worksheet.GetFirstChild方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.GetFirstChild方法的具体用法?C# Worksheet.GetFirstChild怎么用?C# Worksheet.GetFirstChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Worksheet的用法示例。


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

示例1: OpenXmlExcelRandomWriter

 internal OpenXmlExcelRandomWriter(OpenXmlExcelConnection connection, string worksheetName, bool createSheetIfNotExists)
 {
     WorksheetName = worksheetName;
     this.connection = connection;
     this.worksheet = connection.GetSheet(worksheetName, createSheetIfNotExists);
     this.sheetData = worksheet.GetFirstChild<SheetData>();
 }
开发者ID:andresmoschini,项目名称:Moschini.Excel,代码行数:7,代码来源:OpenXmlExcelRandomWriter.cs

示例2: AddRow

        public void AddRow(Worksheet worksheet, bool isHeader, params object[] values)
        {
            var row = new Row();
            var sheetData = worksheet.GetFirstChild<SheetData>();
            var styleIndex = StyleConst.CellFormat.CellFormatStyle.CELL_REGULAR;

            if (isHeader)
                styleIndex = StyleConst.CellFormat.CellFormatStyle.CELL_HEADER;

            foreach (var value in values)
            {
                var cell = GetCell(value, styleIndex);
                row.AppendChild(cell);
            }

            sheetData.Append(row);
            worksheet.Save();
        }
开发者ID:haimtz,项目名称:OpenXml-demo,代码行数:18,代码来源:OpenXmlWrapper.cs

示例3: GetSpreadsheetCell

        // Given a worksheet, a column name, and a row index, gets the cell at the specified column and row.
        private static Cell GetSpreadsheetCell(Worksheet worksheet, string columnName, uint rowIndex)
        {
            IEnumerable<Row> rows = worksheet.GetFirstChild<SheetData>().Elements<Row>().Where(r => r.RowIndex == rowIndex);
            if (rows.Count() == 0)
            {
                // A cell does not exist at the specified row.
                return null;
            }

            IEnumerable<Cell> cells = rows.First().Elements<Cell>().Where(c => string.Compare(c.CellReference.Value, columnName + rowIndex, true) == 0);
            if (cells.Count() == 0)
            {
                // A cell does not exist at the specified column, in the specified row.
                return null;
            }

            return cells.First();
        }
开发者ID:aspose-cells,项目名称:Aspose.Cells-for-.NET,代码行数:19,代码来源:Program.cs

示例4: RetrieveCellReference

        // Given a Worksheet and an address (like "AZ254"), either return a cell reference, or
        // create the cell reference and return it.
        private static Cell RetrieveCellReference(Worksheet ws, string addressName)
        {
            // Use regular expressions to get the row number and column name.
            // If the parameter wasn't well formed, this code
            // will fail:
            Regex rx = new Regex("^(?<col>\\D+)(?<row>\\d+)");
            Match m = rx.Match(addressName);
            uint rowNumber = uint.Parse(m.Result("${row}"));
            string colName = m.Result("${col}");

            // Retrieve reference to the sheet's data.
            SheetData sheetData = ws.GetFirstChild<SheetData>();

            // If the worksheet does not contain a row
            // with the specified row index, insert one.
            var rows = sheetData.Elements<Row>();
            var theRow = rows.FirstOrDefault(r => r.RowIndex.Value == rowNumber);
            if (theRow == null)
            {
                theRow = new Row();
                theRow.RowIndex = rowNumber;

                Row refRow = null;
                foreach (Row row in rows)
                {
                    if (row.RowIndex > rowNumber)
                    {
                        refRow = row;
                        break;
                    }
                }
                // If refRow is null, InsertBefore appends.
                sheetData.InsertBefore(theRow, refRow);
            }
            // At this point, theRow refers to the row to contain the cell value.
            // The cell may or may not exist.

            // If the cell you need already exists, return it.
            // If there is not a cell with the specified address name, insert one.
            var cells = theRow.Elements<Cell>();

            Cell theCell = cells.FirstOrDefault(c => c.CellReference.Value == addressName);
            if (theCell == null)
            {
                // Cell doesn't exist, so create one.
                theCell = new Cell();
                theCell.CellReference = addressName;
                // Must insert cell in the appropriate location.
                Cell refCell = null;
                foreach (Cell cell in cells)
                {
                    if (string.Compare(cell.CellReference.Value, addressName, true) > 0)
                    {
                        refCell = cell;
                        break;
                    }
                }
                // If refCell is null, InsertBefore appends.
                theRow.InsertBefore(theCell, refCell);
            }
            return theCell;
        }
开发者ID:DenMantm,项目名称:C-_open_xml_doc_generator,代码行数:64,代码来源:Form1.cs

示例5: GetRow

 // Given a worksheet and a row index, return the row.
 private Row GetRow(Worksheet worksheet, uint rowIndex)
 {
     return worksheet.GetFirstChild<SheetData>().
       Elements<Row>().Where(r => r.RowIndex == rowIndex).First();
 }
开发者ID:kavamara,项目名称:CAMS_ETL,代码行数:6,代码来源:ConvertExcelToXml.cs

示例6: InsertCellInWorksheet

        // Given a Worksheet and an address (like "AZ254"), either return a 
        // cell reference, or create the cell reference and return it.
        private static DocumentFormat.OpenXml.Spreadsheet.Cell InsertCellInWorksheet(Worksheet ws,
            string addressName)
        {
            SheetData sheetData = ws.GetFirstChild<SheetData>();
            DocumentFormat.OpenXml.Spreadsheet.Cell cell = null;

            UInt32 rowNumber = GetRowIndex(addressName);
            Row row = GetRow(sheetData, rowNumber);

            // If the cell you need already exists, return it.
            // If there is not a cell with the specified column name, insert one.  
            DocumentFormat.OpenXml.Spreadsheet.Cell refCell = row.Elements<DocumentFormat.OpenXml.Spreadsheet.Cell>().
                Where(c => c.CellReference.Value == addressName).FirstOrDefault();
            if (refCell != null)
            {
                cell = refCell;
            }
            else
            {
                cell = CreateCell(row, addressName);
            }
            return cell;
        }
开发者ID:paopaofeng,项目名称:dp2,代码行数:25,代码来源:ExcelUtil.cs

示例7: CreateRow

        // 创建一个 Row。不负责查重
        // row 的 cell 创建完成后,记得 ws.Save()
        public static Row CreateRow(
            Worksheet ws,
            // string addressName,
            UInt32 rowNumber)
        {
            SheetData sheetData = ws.GetFirstChild<SheetData>();

            // UInt32 rowNumber = GetRowIndex(addressName);
            Row row = new Row();
            row.RowIndex = rowNumber;
            sheetData.Append(row);

            return row;
        }
开发者ID:paopaofeng,项目名称:dp2,代码行数:16,代码来源:ExcelUtil.cs

示例8: InsertMergeCell

        public static MergeCell InsertMergeCell(Worksheet ws,
    string addressName1,
    string addressName2)
        {
            SheetData sheetData = ws.GetFirstChild<SheetData>();
            MergeCells cells = ws.GetFirstChild<MergeCells>();
            if (cells == null)
            {
                cells = new MergeCells();
                ws.InsertAfter<MergeCells>(cells, sheetData);
            }

            string s = addressName1 + ":" + addressName2;

            MergeCell cell = cells.Elements<MergeCell>().Where(c => c.Reference == s).FirstOrDefault();
            if (cell == null)
            {
                cell = new MergeCell();
                cell.Reference = s;
                cells.AppendChild<MergeCell>(cell);
            }

            return cell;
        }
开发者ID:paopaofeng,项目名称:dp2,代码行数:24,代码来源:ExcelUtil.cs

示例9: insertCellInWorkSheet

 //
 //  Insert a new cell into the Worksheet at the given address
 //
 private Cell insertCellInWorkSheet(Worksheet ws, string addr)
 {
     //  Select the sheet data
     SheetData sheetData = ws.GetFirstChild<SheetData>();
     Cell cell = null;
     //  Get the row
     UInt32 rowNum = getRowIndex(addr);
     Row row = getRow(sheetData, rowNum);
     //
     //  If the selected cell already exists return it else create a new one
     //
     Cell refCell = row.Elements<Cell>().Where(c => c.CellReference.Value == addr).FirstOrDefault();
     if (refCell != null)
     {
         cell = refCell;
     }
     else
     {
         cell = createCell(row, addr);
     }
     return cell;
 }
开发者ID:Rossano,项目名称:Dome_Control,代码行数:25,代码来源:LogLib.cs

示例10: SelectSheet

        private bool SelectSheet(string nomeAba)
        {
            Sheet aba = _wbPart.Workbook.Descendants<Sheet>().ToList().FirstOrDefault(s => s.Name == nomeAba);

            if (aba != null)
            {
                _activeWorksheet = ((WorksheetPart)(_wbPart.GetPartById(aba.Id))).Worksheet;
                _controlesFolhaAtual = _activeWorksheet.GetFirstChild<Controls>();

                return true;
            }

            return false;
        }
开发者ID:AmandaMakino,项目名称:SisUrbe,代码行数:14,代码来源:OpenXmlHelper.cs

示例11: InsertCellInWorksheet

        private Cell InsertCellInWorksheet(Worksheet ws, string addressName)
        {
            var sheetData = ws.GetFirstChild<SheetData>();
            Cell cell = null;

            var rowNumber = GetRowIndex(addressName);
            var row = GetRow(sheetData, rowNumber);

            var refCell = row.Elements<Cell>().FirstOrDefault(c => c.CellReference.Value == addressName);
            cell = refCell ?? CreateCell(row, addressName);
            return cell;
        }
开发者ID:gerasyana,项目名称:Academy,代码行数:12,代码来源:ExcellWorker.cs

示例12: GetRow

 // Given a worksheet and a row index, return the row.
 private static Row GetRow(Worksheet worksheet, uint rowIndex)
 {
     var rows = worksheet.GetFirstChild<SheetData>().Elements<Row>().ToArray();
     return rows.FirstOrDefault(r => r.RowIndex == rowIndex);
 }
开发者ID:RavingRabbit,项目名称:Labs,代码行数:6,代码来源:SpreadsheetEditor.cs

示例13: GetRow

 // Given a worksheet and a row index, return the row.
 public static Row GetRow(Worksheet worksheet, uint rowIndex)
 {
     Row row = worksheet.GetFirstChild<SheetData>().Elements<Row>().ElementAtOrDefault((int)rowIndex - 1);
     return row;
 }
开发者ID:heimanhon,项目名称:researchwork,代码行数:6,代码来源:ExcelTools.cs

示例14: CreateRow

 public static Row CreateRow(Worksheet worksheet, uint rowIndex)
 {
     Row row = worksheet.GetFirstChild<SheetData>().AppendChild(new Row());
     row.RowIndex = rowIndex;
     return row;
     
 }
开发者ID:heimanhon,项目名称:researchwork,代码行数:7,代码来源:ExcelTools.cs

示例15: GetRow

 // Given a worksheet and a row index, return the row.
 private static Row GetRow(Worksheet worksheet, uint rowIndex)
 {
     Row row;
     SheetData sheetData = worksheet.GetFirstChild<SheetData>();
     if (sheetData.Elements<Row>().Where(item => item.RowIndex == rowIndex).Count() != 0)
     {
         row = sheetData.Elements<Row>().Where(item => item.RowIndex == rowIndex).First();
     }
     else
     {
         Row previousRow = null;
         row = new Row() { RowIndex = rowIndex };
         for (uint counter = rowIndex - 1; counter > 0; counter--)
         {
             previousRow = sheetData.Elements<Row>().Where(item => item.RowIndex == counter).FirstOrDefault();
             if (previousRow != null)
             {
                 break;
             }
         }
         sheetData.InsertAfter(row, previousRow);
     }
     return row;
 }
开发者ID:modulexcite,项目名称:StudentSuccessDashboard,代码行数:25,代码来源:ExcelUtility.cs


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