如何使用 Microsoft interop 将工作表开头的新列添加到现有 Excel
我有一个 8 列的 Excel。我正在尝试在工作表的开头添加一个新列。现有的列应该移动。
下面是我尝试过的代码:
OpenExcelWorkbook(@"d:\TLC\TLC3.xlsx");
_sheet = (Excel.Worksheet)_sheets[1];
_sheet.Select(Type.Missing);
_sheet.Columns.Insert(1, 1);
但我收到以下错误:
为了防止可能的数据丢失,Excel 无法将非空白单元格移出工作表。选择另一个位置来插入新单元格,或从工作表末尾删除数据。如果单元格中没有可以从工作表中移出的数据,您可以重置 Excel 视为非空白的单元格。为此,请按 CTRL+End 找到工作表上的最后一个非空白单元格。删除此单元格以及它与数据的最后一行和最后一列之间的所有单元格,然后保存。
I have an excel with 8 columns. I'm trying to add a new column at the beginning of the worksheet. The existing columns should shift.
Below is the code which I tried:
OpenExcelWorkbook(@"d:\TLC\TLC3.xlsx");
_sheet = (Excel.Worksheet)_sheets[1];
_sheet.Select(Type.Missing);
_sheet.Columns.Insert(1, 1);
But I'm getting the following error:
To prevent possible loss of data, Excel cannot shift nonblank cells off of the worksheet. Select another location in which to insert new cells, or delete data from the end of your worksheet. If you do not have data in cells that can be shifted off of the worksheet, you can reset which cells Excel considers nonblank. To do this, press CTRL+End to locate the last nonblank cell on the worksheet. Delete this cell and all cells between it and the last row and column of your data then save.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将插入语句更改为
Change your insert statement to
以下代码对我有用......
The following code worked for me...