a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

c#在excel中添加超鏈接示例分享

2020-01-24 02:59:13
字體:
來源:轉載
供稿:網友

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://www.baidu.com",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();
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩高清国产一区在线 | 91在线一区二区 | 亚洲成人av在线 | 本道综合精品 | 97久久精品 | 91久久精品一区二区二区 | 一区二区三区免费在线观看 | 污视频网站在线观看免费 | 在线免费观看色视频 | 天天色天天看 | 99精品网 | av 一区二区三区 | 正在播放亚洲 | 久久se精品一区精品二区 | 妞干网视频 | 成人在线一区二区三区 | 成人欧美一区二区三区在线播放 | 免费看的av | 精品国产一区二区三区在线观看 | 日韩一区二区精品 | 日本黄色一级片免费看 | 久久天天 | 亚洲美女一区二区三区 | 91在线观看视频 | 日韩欧美精品 | 一区二区三区国产好 | 淫语对白 | 91视频爱爱 | 亚洲永久 | 精品一区二区三区在线观看 | 欧美色综合一区二区三区 | 一区二区三区在线播放视频 | 91久色| 国产精品久久久久久久久久久久久久久久久 | 中文字幕一区二区三区四区不卡 | 五月综合婷 | 99热影院 | 欧美日韩在线一区 | 国产欧美精品区一区二区三区 | 日韩精品免费视频 | 亚洲激情在线 |