c# xls 复制一行_【022】◀▶ C# 操作 Office 文件c# 操作Excel(标题行,页脚,行高,边框..)使用VSTO复制部分Excel单元格(带格式),粘贴并保存到另一Excel文件...

本文介绍了如何使用C#和VSTO来操作Excel,包括复制Excel的一部分单元格(包括格式)并粘贴到另一个Excel文件中。详细讲解了Application、Workbook、Worksheet等接口及其属性和方法,例如ActiveCell、Range、Copy、PasteSpecial等,以实现Excel文件的读取、修改和保存。
摘要由CSDN通过智能技术生成

---------------------------------------------------------------------------------------------------------

●·● 目录:

---------------------------------------------------------------------------------------------------------

Application 接口:Represents the entire Microsoft Excel application.【继承于:_Application 接口】

Workbook 接口:Represents a Microsoft Excel workbook.【继承于:_Workbook 接口】

Worksheet 接口:Represents a worksheet.【继承于:_Worksheet 接口】

---------------------------------------------------------------------------------------------------------

╔════════╗

╠════╣    第A1个    ╠══════════════════════════════════════════════════╣

╚════════╝

1. Represents the entire Microsoft Excel application.

2. _Application 属性:

Application:基本上具有 _Application 的调用!

ActiveCell:Returns a Range object that represents the active cell in the active window (the window on top) or in the specified window. →返回当前选择的 Range 对象!

Excel.Range range =ex.ActiveCell;    //赋值到一个 Range 对象

MessageBox.Show(range.Row.ToString());  //获取行号

MessageBox.Show(range.Column.ToString());  //获取列号

ActiveChart:Returns a Chart object that represents the active chart (either an embedded chart or a chart sheet).

ActiveSheet:Returns an object that represents the active sheet (the sheet on top) in the active workbook or in the specified window or workbook. →返回当前的工作表对象!

Excel.Worksheet sheet = ex.ActiveSheet;

ActiveWorkbook:Returns a Workbookobject that represents the workbook in the active window (the window on top). →返回当前的工作簿对象!

Excel.Workbook book = ex.ActiveWorkbook;

Caption:The name that appears in the title bar of the main Microsoft Excel window.

Cursor:Returns or sets the appearance of the mouse pointer in Microsoft Excel.【返回:XlMousePointer】→鼠标显示样式!

CutCopyMode:Returns or sets the status of Cut or Copy mode.【返回:XlCutCopyMode】→选择框是否保留!

Sheets:Returns a Sheets collection that represents all the sheets in the active workbook. →返回所有工作表!

ThisWorkbook:Returns a Workbook object that represents the workbook where the current macro code is running. →返回当前工作表!

Top:The distance, in points, from the top edge of the screen to the top edge of the main Microsoft Excel window.

Left:The distance, in points, from the left edge of the screen to the left edge of the main Microsoft Excel window.

Height:The height, in points, of the main application window.

Columns:Returns a Range object that represents all the columns on the active worksheet. →返回所有列

Rows:Returns a Range object that represents all the rows on the active worksheet. →返回所有行

Cells:Returns a Range object that represents all the cells on the active worksheet. →返回所有单元格

long count =ex.Cells.CountLarge;    //用 Count 会出错!

MessageBox.Show(count.ToString());  //显示所有的单元格个数!

Visible:Determines whether the object is visible. →是否可见!

UserName:Returns or sets the name of the current user.

Value:Returns "Microsoft Excel".

Version:Determines whether the object is visible.

WindowState:Returns or sets the state of the window.【返回:XlWindowState】→最大化、最小化等!

Workbooks:Returns a Workbooks collection that represents all the open workbooks. →返回所有工作簿!

Worksheets:Returns a Sheets collection that represents all the worksheets in the active workbook. →返回所有工作表!

3. _Application 方法:

InputBox:Displays a dialog box for user input. Returns the information entered in the dialog box.

Quit:Quits Microsoft Excel.

---------------------------------------------------------------------------------------------------------

╔════════╗

╠════╣    第A2个    ╠══════════════════════════════════════════════════╣

╚════════╝

1. A collection of all the Workbook objects that are currently open in the Microsoft Excel application.

2. Workbooks 属性:

Application:

Count:Returns the number of objects in the collection. Read-only Integer.

Item:Returns a single object from a collection.【类似数组的用法】

Parent:Returns the parent object for the specified object. Read-only.

3. Workbooks 方法:

Add:Creates a new workbook. The new workbook becomes the active workbook. Returns a Wor

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值