Gembox Spreadsheet添加列,但不删除其他列 [英] Gembox Spreadsheet add column without remove the other ones

查看:129
本文介绍了Gembox Spreadsheet添加列,但不删除其他列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用c#进行编码,并使用Gembox Spreadsheet来操纵excel文件. 我想知道是否可以在先前存在的xls文件中添加一列(不删除其他列):

I'm coding in c# and using Gembox Spreadsheet to manipulate excel files. I'd like to know if it's possible to add a column(without remove the other ones) in a pre-existent xls file:

ExcelFile ef = ExcelFile.Load(masterFile);
ExcelWorksheet ws = ef.Worksheets["Peer Review"];
DataTable dataTable = new DataTable();
dataTable.Columns.Add("Standard Deviation", typeof(double));
ws.InsertDataTable(dataTable, new InsertDataTableOptions()
            {
                ColumnHeaders = true,
                StartRow = 0,
                StartColumn = 15
            });
ef.Save(masterFile);

以我提到的方式,我可以在位置"15"处插入新列,但以相同的方式删除第15个旧列.因此,我想插入一列而不删除其他列.

In the way I mentioned I can insert a new column at position "15" but in the same way the 15th old column is removed. So I'd like to insert a column without removing the other ones.

推荐答案

InsertDataTable方法将DataTable的数据插入指定的单元格区域,它们不会插入新的Excel行或列.

InsertDataTable methods insert the DataTable's data into specified cell range, they do not insert new excel rows nor columns.

因此,您可以做的是通过添加空列来显式地为所需的插入操作腾出空间,例如:

So what you can do is explicitly make room for the desired insertion by adding an empty columns, for example:

ws.Columns.InsertEmpty(15, dataTable.Columns.Count);
ws.InsertDataTable(dataTable, new InsertDataTableOptions()
{
    ColumnHeaders = true,
    StartRow = 0,
    StartColumn = 15
});

这篇关于Gembox Spreadsheet添加列,但不删除其他列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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