时间:2021-05-20
1.新建一个项目
2.给项目添加引用:Microsoft Excel 12.0 Object Library (2007版本)
复制代码 代码如下:
using Excel = Microsoft.Office.Interop.Excel;
3.对excel的简单操作:如下代码“添加超链接”等。
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelExample
{
class Program
{
static void Main(string[] args)
{
Excel.Application excelApp = new Excel.Application(); // Creates a new Excel Application
excelApp.Visible = true; // Makes Excel visible to the user.
// The following line if uncommented adds a new workbook
//Excel.Workbook newWorkbook = excelApp.Workbooks.Add();
// The following code opens an existing workbook
string workbookPath = "F:\\11.xlsx"; // Add your own path here
Excel.Workbook excelWorkbook = null;
try
{
excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
false, 0, true, false, false);
}
catch
{
//Create a new workbook if the existing workbook failed to open.
excelWorkbook = excelApp.Workbooks.Add();
}
// The following gets the Worksheets collection
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
// The following gets Sheet1 for editing
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
// The following gets cell A1 for editing
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "B1");
// The following sets cell A1's value to "Hi There"
excelCell.Value2 = "Hi There";
Excel.Worksheet excelWorksheet2 = (Excel.Worksheet)excelSheets.get_Item("Sheet2");
Excel.Range excelCell2 = (Excel.Range)excelWorksheet2.get_Range("A1", Type.Missing);
excelCell2.Value2 = "Hi Here";
// Add hyperlinks to the cell A1
//excelWorksheet.Hyperlinks.Add(excelCell,"http:\\",Type.Missing,"baidu",Type.Missing);
// Add hyperlinks from "sheet1 A1" to "sheet2 A1"
excelWorksheet.Hyperlinks.Add(excelCell, "#Sheet2!A1", Type.Missing, Type.Missing, Type.Missing);
// Close the excel workbook
//excelWorkbook.Close(true,Type.Missing,Type.Missing);
//Quit the excel app
//excelApp.Quit();
}
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
在制作excel表格时,我们常常会添加一些超链接,让表格内容更丰富,今天小编就为大家介绍一下excel2010中怎么添加超链接。 首先选中需要添加超链接的
在制作excel表格时,常常会添加一些超链接,让表格内容更丰富,下面就为大家介绍一下excel2010中怎么添加超链接。 首先选中需要添加超链接的单元格,
在Excel表格中插入超链接的话,可以使表格内容更加丰富,拓展更加多元化,那么在excel表格中怎么添加超链接呢?下面为大家详细介绍一下,来看看吧! 步骤
在Excel表格中插入超链接的话,可以使表格内容更加丰富,拓展更加多元化,那么在excel表格中怎么添加超链接呢?下面小编就为大家详细介绍一下,来看看吧!作用:
想要使用VBA程序在Excel中批量添加超链接;将Excel其中一个工作表的某列添加另外一个工作表的某列的超链接。下面我们就来看看详细的教程。软件名称:Micr