如何用c#在excel中插入行 [英] How to insert row in excel with c#

查看:422
本文介绍了如何用c#在excel中插入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#在Excel中插入空闲行?

解决方案

从C#操作Excel文件的一种方法是使用Interop。要开始使用它,请查看如何:访问Office使用Visual C#功能的互操作对象(C#编程指南) [ ^ ]。



一旦创建了对Excel对象,工作表等的正确引用,使用 Range.Insert方法(Microsoft.Office.Interop.Excel) [ ^ ]为所需位置腾出空间。



请注意,如果你想创建一个新行,那么使用的范围应该是一行,例如

 myworksheet.Rows(  5:5)。插入(xlDirection.xlDown,XlInsertFormatOrigin。 xlFormatFromLeftOrAbove); 


How to insert free row in excel with c#?

解决方案

One way to manipulate an Excel file from C# is to use Interop. To get started with it, have a look at for example How to: Access Office Interop Objects by Using Visual C# Features (C# Programming Guide)[^].

Once you have created proper references to Excel object, the worksheet and so on, use Range.Insert method (Microsoft.Office.Interop.Excel)[^] to make space to a desired position.

Note that if you want to make a new row the range to use should be a row, something like

myworksheet.Rows("5:5").Insert(xlDirection.xlDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);


这篇关于如何用c#在excel中插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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