最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2013年12月22日 10:07:13   作者:  
c#在excel中添加超鏈接示例分享,大家參考使用吧

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();
        }
    }
}

相關文章

最新評論

花垣县| 望奎县| 吉水县| 大渡口区| 迁西县| 鹤庆县| 濮阳市| 北票市| 六安市| 汉中市| 钟祥市| 始兴县| 西充县| 阿坝县| 松原市| 丰县| 崇仁县| 阿拉尔市| 鄄城县| 栾川县| 桑植县| 邹平县| 常州市| 蚌埠市| 陈巴尔虎旗| 枞阳县| 开原市| 元阳县| 都匀市| 黄平县| 罗定市| 深圳市| 长治市| 奎屯市| 永德县| 襄樊市| 五原县| 商水县| 云林县| 上虞市| 曲水县|