无法使用Microsoft.Office.Interop.Excel C#将对象嵌入到Excel文件中

时间:2018-12-18 13:30:21

标签: c# excel

我正在尝试使用Microsoft.Office.Interop.Excel嵌入对象,但得到一张空白纸。 这是我的代码

  public static void ExcelInsertOLE(string objectPath, string filePath,string discipline)
    {

        Microsoft.Office.Interop.Excel.Application excel = new Application();
        //  excel.Workbooks.Add();
        Microsoft.Office.Interop.Excel.Workbook workBook = excel.Workbooks.Open(filePath);
       // Microsoft.Office.Interop.Excel.Worksheet sheet = (Worksheet)workBook.Worksheets.Add();

        Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)excel.Worksheets.Add(Type.Missing, excel.Worksheets[excel.Worksheets.Count], 1, XlSheetType.xlWorksheet);
        sheet.Name = discipline;

      //  OLEObjects oleObjects = (Microsoft.Office.Interop.Excel.OLEObjects)sheet.OLEObjects(Type.Missing);
        sheet.Shapes.AddOLEObject(ClassType: Type.Missing, Filename: objectPath, Link: true);

        workBook.Close(true);
        excel.Quit();
    }

谢谢。

0 个答案:

没有答案