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


C# Row.AppendChild方法代码示例

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


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

示例1: Run

        public static void Run()
        {
            // ExStart:InsertTableDirectly
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithTables();

            Document doc = new Document();
            // We start by creating the table object. Note how we must pass the document object
            // To the constructor of each node. This is because every node we create must belong
            // To some document.
            Table table = new Table(doc);
            // Add the table to the document.
            doc.FirstSection.Body.AppendChild(table);

            // Here we could call EnsureMinimum to create the rows and cells for us. This method is used
            // To ensure that the specified node is valid, in this case a valid table should have at least one
            // Row and one cell, therefore this method creates them for us.

            // Instead we will handle creating the row and table ourselves. This would be the best way to do this
            // If we were creating a table inside an algorthim for example.
            Row row = new Row(doc);
            row.RowFormat.AllowBreakAcrossPages = true;
            table.AppendChild(row);

            // We can now apply any auto fit settings.
            table.AutoFit(AutoFitBehavior.FixedColumnWidths);

            // Create a cell and add it to the row
            Cell cell = new Cell(doc);
            cell.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue;
            cell.CellFormat.Width = 80;

            // Add a paragraph to the cell as well as a new run with some text.
            cell.AppendChild(new Paragraph(doc));
            cell.FirstParagraph.AppendChild(new Run(doc, "Row 1, Cell 1 Text"));

            // Add the cell to the row.
            row.AppendChild(cell);

            // We would then repeat the process for the other cells and rows in the table.
            // We can also speed things up by cloning existing cells and rows.
            row.AppendChild(cell.Clone(false));
            row.LastCell.AppendChild(new Paragraph(doc));
            row.LastCell.FirstParagraph.AppendChild(new Run(doc, "Row 1, Cell 2 Text"));
            dataDir = dataDir + "Table.InsertTableUsingNodes_out.doc";
            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:InsertTableDirectly
            Console.WriteLine("\nTable using notes inserted successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:50,代码来源:InsertTableDirectly.cs

示例2: CreateNewRow

        private static Row CreateNewRow(int rowIndex, params string[] data)
        {
            // New Row
            Row row = new Row { RowIndex = (UInt32)rowIndex };

            for (int i = 0; i < data.Length; i++)
            {
                // A = 65 for the first column, B = 66, C = 67...
                string column = ((char) (65 + i)).ToString();

                // New Cell
                Cell cell = new Cell
                                {
                                    DataType = CellValues.InlineString,
                                    CellReference = column + rowIndex
                                };

                // Create Text object
                Text t = new Text {Text = data[i]};

                // Append Text to InlineString object
                InlineString inlineString = new InlineString();
                inlineString.AppendChild(t);

                // Append InlineString to Cell
                cell.AppendChild(inlineString);

                // Append Cell to Row
                row.AppendChild(cell);
            }
            return row;
        }
开发者ID:stevenh77,项目名称:CreatingExcelFile,代码行数:32,代码来源:Program.cs

示例3: GenerateReport

        public static void GenerateReport(List<DataObject> objects)
        {
            SheetData data = new SheetData();

              //add column names to the first row
              Row header = new Row();
              header.RowIndex = (UInt32)1;

              foreach (DataObject obj in objects)
              {
            Cell headerCell = createTextCell(objects.IndexOf(obj) + 1, 1, obj.Name);
            header.AppendChild(headerCell);
              }
              data.AppendChild(header);
              SpreadsheetDocument doc = CreateDoc(data);
              /*using (SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(fileName, true))
              {
            WorkbookPart workbook = spreadsheet.WorkbookPart;
            //create a reference to Sheet1
            WorksheetPart worksheet = workbook.WorksheetParts.Last();

            ///loop through each data row  DataRow contentRow;
            for (int i = 0; i < table.Rows.Count; i++)
            {
              contentRow = table.Rows[i];
              data.AppendChild(createContentRow(contentRow, i + 2));
            }
               }  */
        }
开发者ID:qreal,项目名称:tools,代码行数:29,代码来源:Integrator.cs

示例4: createContentRow

        private static Row createContentRow(
      int rowIndex, string text)
        {
            Row row = new Row { RowIndex = (UInt32)rowIndex };

              Cell dataCell = createTextCell(1, rowIndex, text);
              row.AppendChild(dataCell);
              return row;
        }
开发者ID:AirVan21,项目名称:tools,代码行数:9,代码来源:Integrator.cs

示例5: addHeaderRow

 //создает строку заголовка
 protected virtual void addHeaderRow(Row headerRow, DataTable dt)
 {
     foreach (DataColumn HeaderColumn in dt.Columns)
     {
         Cell cell = new Cell() { StyleIndex = (UInt32Value)0U };
         cell.DataType = CellValues.String;
         cell.CellValue = new CellValue(HeaderColumn.ColumnName);
         headerRow.AppendChild(cell);
     }
 }
开发者ID:AlexKrainov,项目名称:ProjectTheRecreation,代码行数:11,代码来源:BaseExcelBuilder.cs

示例6: GenerateExcel

        public MemoryStream GenerateExcel(SLExcelData data)
        {
            var stream = new MemoryStream();
            var document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook);

            var workbookpart = document.AddWorkbookPart();
            workbookpart.Workbook = new Workbook();
            var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
            var sheetData = new SheetData();

            worksheetPart.Worksheet = new Worksheet(sheetData);

            var sheets = document.WorkbookPart.Workbook.
                AppendChild<Sheets>(new Sheets());

            var sheet = new Sheet() {
                Id = document.WorkbookPart.GetIdOfPart(worksheetPart),
                SheetId = 1, Name = data.SheetName ?? "Sheet 1"
            };
            sheets.AppendChild(sheet);

            // Add header
            UInt32 rowIdex = 0;
            var row = new Row { RowIndex = ++rowIdex };
            sheetData.AppendChild(row);
            var cellIdex = 0;

            foreach (var header in data.Headers) {
                row.AppendChild(CreateTextCell(ColumnLetter(cellIdex++), rowIdex, header ?? string.Empty));
            }
            if (data.Headers.Count > 0) {
                // Add the column configuration if available
                if (data.ColumnConfigurations != null) {
                    var columns = (Columns)data.ColumnConfigurations.Clone();
                    worksheetPart.Worksheet
                        .InsertAfter(columns, worksheetPart.Worksheet.SheetFormatProperties);
                }
            }

            // Add sheet data
            foreach (var rowData in data.DataRows) {
                cellIdex = 0;
                row = new Row { RowIndex = ++rowIdex };
                sheetData.AppendChild(row);
                foreach (var callData in rowData) {
                    var cell = CreateTextCell(ColumnLetter(cellIdex++), rowIdex, callData ?? string.Empty);
                    row.AppendChild(cell);
                }
            }

            workbookpart.Workbook.Save();
            document.Close();

            return stream;
        }
开发者ID:karthikeyanar,项目名称:wvcnet,代码行数:55,代码来源:SLExcelWriter.cs

示例7: CreateHeaderRow

 protected virtual Row CreateHeaderRow(IEnumerable<string> headers)
 {
     var row = new Row();
     foreach (var columnName in headers)
     {
         var cell = new Cell
                    {
                        DataType = CellValues.String,
                        CellValue = new CellValue(columnName)
                    };
         row.AppendChild(cell);
     }
     return row;
 }
开发者ID:junshao,项目名称:Medidata.Cloud.Tsdv.Loader,代码行数:14,代码来源:HeaderSheetDecorator.cs

示例8: CreateContentRow

        private Row CreateContentRow(DataGridViewRow dataRow, int startRowIndex)
        {
            var row = new Row { RowIndex = (UInt32)startRowIndex };

            for (var i = 0; i < _headerColumns.Length; i++)
            {
                var cell = _factory.Create(dataRow.Cells[i].Value);
                cell.CellReference = _headerColumns[i] + startRowIndex;

                row.AppendChild(cell);
            }

            return row;
        }
开发者ID:raman-kashyap,项目名称:Practices,代码行数:14,代码来源:DatabaseListView2.cs

示例9: ImportDataTable

        public void ImportDataTable(SpreadsheetDocument package, DataTable table, string sheetName)
        {
            //populate the data into the spreadsheet
            WorkbookPart workbook = package.WorkbookPart;

            WorksheetPart worksheetPart = workbook.AddNewPart<WorksheetPart>();
            worksheetPart.Worksheet = new Worksheet(new SheetData());

            SheetData data = worksheetPart.Worksheet.GetFirstChild<SheetData>();

            //add column names to the first row
            Row header = new Row();
            header.RowIndex = (UInt32)1;

            foreach (DataColumn column in table.Columns) {
                Cell headerCell = CreateTextCell(
                    table.Columns.IndexOf(column) + 1,
                    1,
                    column.ColumnName);

                header.AppendChild(headerCell);
            }
            data.AppendChild(header);

            //loop through each data row
            DataRow contentRow;
            for (int i = 0; i < table.Rows.Count; i++) {
                contentRow = table.Rows[i];
                data.AppendChild(CreateContentRow(contentRow, i + 2));
            }

            // Create Sheets object.
            Sheets sheets = workbook.Workbook.GetFirstChild<Sheets>();
            string relationshipId = workbook.GetIdOfPart(worksheetPart);

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

            // Append the new worksheet and associate it with the workbook.
            Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName };
            sheets.Append(sheet);
        }
开发者ID:FerHenrique,项目名称:Owl,代码行数:45,代码来源:DataTableImporter.cs

示例10: 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

示例11: ExportDataTable

        public void ExportDataTable(DataTable table, string exportFile)
        {
            //create the empty spreadsheet template and save the file //using the class generated by the Productivity tool
            ExcelDocument excelDocument = new ExcelDocument();
            excelDocument.CreatePackage(exportFile);
            //string filename = "";
            //File.Copy(filename, filename, true);
            //populate the data into the spreadsheet
            using (SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(exportFile, true))
            {
                WorkbookPart workbook = spreadsheet.WorkbookPart;
                //create a reference to Sheet1
                WorksheetPart worksheet = workbook.WorksheetParts.Last();
                SheetData data = worksheet.Worksheet.GetFirstChild<SheetData>();

                //add column names to the first row
                Row header = new Row();
                header.RowIndex = (UInt32)1;

                foreach (DataColumn column in table.Columns)
                {
                    Cell headerCell = createTextCell(
                        table.Columns.IndexOf(column) + 1,
                        1,
                        column.ColumnName);

                    header.AppendChild(headerCell);
                }
                data.AppendChild(header);

                //loop through each data row
                DataRow contentRow;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    contentRow = table.Rows[i];
                    data.AppendChild(createContentRow(contentRow, i + 2));
                }
            }
        }
开发者ID:kaganyuksel,项目名称:esm,代码行数:39,代码来源:ReportesMen.aspx.cs

示例12: BuildRowFromExpandoObject

        private Row BuildRowFromExpandoObject(SheetModel model, ISheetDefinition sheetDefinition)
        {
            var row = new Row();
            foreach (var columnDefinition in sheetDefinition.ColumnDefinitions)
            {
                var propValue = GetPropertyValue(model, columnDefinition.PropertyName);
                CellValues cellType;
                string cellValue;
                _converterManager.GetCellTypeAndValue(propValue, out cellType, out cellValue);
                var cell = new Cell
                           {
                               DataType = cellType,
                               CellValue = new CellValue(cellValue)
                           };
                cell.AddMdsolAttribute("type",
                    propValue == null ? typeof(object).FullName : propValue.GetType().FullName);
                cell.AddMdsolAttribute("propertyName", columnDefinition.PropertyName);
                row.AppendChild(cell);
            }

            return row;
        }
开发者ID:junshao,项目名称:Medidata.Cloud.Tsdv.Loader,代码行数:22,代码来源:SheetBuilder.cs

示例13: GenerateReport

        public static void GenerateReport(List<DataObject> objects)
        {
            const string fileName = @"C:\Users\Masha\report.xlsx";
              using (SpreadsheetDocument doc = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook))
              {
            WorkbookPart workbook = doc.WorkbookPart;
            WorksheetPart worksheet = workbook.WorksheetParts.Last();
            SheetData data = worksheet.Worksheet.GetFirstChild<SheetData>();

            //add column names to the first row
            Row header = new Row();
            header.RowIndex = (UInt32)1;

            Cell headerCell = createTextCell(1, 1, "header");
            header.AppendChild(headerCell);
            data.AppendChild(header);

            for (int i = 0; i < objects.Count; i++)
            {
              data.AppendChild(createContentRow(i + 2, objects[i].Name));
            }
              }
        }
开发者ID:AirVan21,项目名称:tools,代码行数:23,代码来源:Integrator.cs

示例14: InsertValuesInSheets

        public static void InsertValuesInSheets(string sheetName, SelectQueryBuilder queryBuilder, WorkbookPart workbookPart, DataTable table)
        {
            WorksheetPart worksheetPart = null;

            if (!string.IsNullOrEmpty(sheetName))
            {
                Sheet ss = workbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == sheetName).SingleOrDefault<Sheet>();
                worksheetPart = (WorksheetPart)workbookPart.GetPartById(ss.Id);
            }
            else
            {
                worksheetPart = workbookPart.WorksheetParts.FirstOrDefault();
            }

            if (worksheetPart != null)
            {
                SheetData data = worksheetPart.Worksheet.GetFirstChild<SheetData>();

                //add column names to the first row  
                Row header = new Row();
                header.RowIndex = (UInt32)1;

                foreach (DataColumn column in table.Columns)
                {
                    Cell headerCell = createTextCell(
                        table.Columns.IndexOf(column) + 1,
                        1,
                        column.ColumnName);

                    header.AppendChild(headerCell);
                }
                data.AppendChild(header);

                //loop through each data row  
                DataRow contentRow;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    contentRow = table.Rows[i];
                    data.AppendChild(createContentRow(contentRow, i + 2));
                }

                worksheetPart.Worksheet.Save();
            }
        }
开发者ID:mukeshdepani,项目名称:ParaRD,代码行数:44,代码来源:Common.cs

示例15: Write

        public void Write(DataTable dt)
        {
            var sheets = _wbPart.Workbook.Descendants<Sheet>();
            int sheetCount = sheets.Count();
            var sheet = sheets.Where(c => c.Name.Value.ToLower() == dt.TableName.ToLower()).FirstOrDefault();
            WorksheetPart wsPart = null;
            if (sheet == null)
            {
                wsPart = _wbPart.AddNewPart<WorksheetPart>();
                wsPart.Worksheet = new Worksheet(new SheetData());
                sheet = new Sheet()
                {
                    Id = _wbPart.GetIdOfPart(wsPart),
                    Name = dt.TableName,
                    SheetId = (uint)(sheetCount + 1)
                };
                _wbPart.Workbook.GetFirstChild<Sheets>().Append(sheet);
            }
            else
            {
                wsPart = _wbPart.GetPartById(sheet.Id) as WorksheetPart;
                wsPart.Worksheet.GetFirstChild<SheetData>().RemoveAllChildren();
            }

            SheetData sheetData = wsPart.Worksheet.GetFirstChild<SheetData>();

            Row headRow = new Row();
            headRow.RowIndex = 1;

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                Cell c = new Cell();
                c.DataType = new EnumValue<CellValues>(CellValues.String);
                c.CellReference = getColumnName(i + 1) + "1";
                c.CellValue = new CellValue(dt.Columns[i].ColumnName);
                headRow.AppendChild(c);
            }
            sheetData.AppendChild(headRow);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Row r = new Row();
                r.RowIndex = (UInt32)i + 2;
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    Cell c = new Cell();
                    c.DataType = new EnumValue<CellValues>(getCellType(dt.Columns[j].DataType));
                    c.CellReference = getColumnName(j + 1) + r.RowIndex.ToString();

                    DataRow dr = dt.Rows[i];

                    if (dr.IsNull(j))
                    {
                        c.CellValue = new CellValue("");
                    }
                    else if (c.DataType.Value == CellValues.Boolean)
                    {
                        string value = bool.Parse(dt.Rows[i][j].ToString()) ? "1" : "0";
                        c.CellValue = new CellValue(value);
                    }
                    else
                    {
                        c.CellValue = new CellValue(dt.Rows[i][j].ToString());
                    }

                    r.Append(c);
                }
                sheetData.Append(r);
            }

            _wbPart.Workbook.Save();
        }
开发者ID:Jason-Brody,项目名称:Young,代码行数:72,代码来源:ExcelHelper.cs


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