如何在SheetData中合并3个单元格。如何从工作表数据中删除一列 [英] How to merge 3 cells in SheetData. How to Delete One column from sheet Data

查看:105
本文介绍了如何在SheetData中合并3个单元格。如何从工作表数据中删除一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我的requiremnet是合并三个excel单元格。我正在使用Open XMl for excel。

另一个要求是从SheetData删除特定列

以下是我用来生成excel文件的方法。 br />
请仔细阅读代码。在那里我提到了我的要求作为评论。



任何帮助都将受到高度赞赏。



Hi Friends,

My requiremnet is to merge three cell of excel. I am using Open XMl for excel.
Another requirement is to delete a particular column from the SheetData
Below is the method which i am using to generate the excel file.
Please go through the code. There i mention my requirement as comments.

Any help will be highly appreciated.

public static void AddToMultipleSheets(WorksheetPart worksheetPart, WorkbookPart workbookPart, DataTable data, int startRow)
{
    Worksheet worksheet = worksheetPart.Worksheet;
    string Id = workbookPart.GetIdOfPart(worksheetPart);
    SheetData sheetData = worksheet.Descendants<SheetData>().FirstOrDefault();
    UInt32Value rowIndex = (UInt32Value)((UInt32)startRow);

    for (int rIndex = 0; rIndex < data.Rows.Count; rIndex++)
    {
        Row row = new Row()
            {
                RowIndex = rowIndex++,
                Spans = new ListValue<StringValue>() { InnerText = "1:3" },
                DyDescent = 0.25D
            };

        for (int cIndex = 0; cIndex < data.Columns.Count; cIndex++)
        {
            Cell cell = new Cell()
            {
                CellReference = ColumnCaption.Instance.Get((Convert.ToInt32((UInt32)rowIndex) - 2), cIndex),
                DataType = CellValues.String
            };
            CellFormat cellFormat = new CellFormat();
            CellValue cellValue = new CellValue();
            cellValue.Text = data.Rows[rIndex][cIndex].ToString();
            // My Requirement is to merge three adjacent cells.
            // If suppose my last column is "J" i need to merge J,K,L and value to placed in the merged cell
            cell.Append(cellValue);
            row.Append(cell);  
        }
        sheetData.Append(row);
        // Other requirment is to delete one column from the sheet data, say "M" Column

    }           
}

推荐答案

请阅读以下内容:

如何:合并电子表格文档中的两个相邻单元格(Open XML SDK) [ ^ ]

如何使用Open XML SDK在Excel中删除列 [ ^ ]
Please, read these:
How to: Merge two adjacent cells in a spreadsheet document (Open XML SDK)[^]
How to Delete a Column in Excel using Open XML SDK[^]


这篇关于如何在SheetData中合并3个单元格。如何从工作表数据中删除一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆