gdqq456gdq
gdqq456gdq
采纳率0%
2021-05-18 18:45 阅读 159
已结题

CVI导出EXCEL中的图片

100

开发环境是Lab Windows CVI,需要通过代码打开EXCEL,并导出该EXCEL中的几张图片到指定文件夹中。需要实现这个功能的代码。

  • 点赞
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • qq_15769939 小P聊技术 2021-05-20 13:33
    using Microsoft.Office.Interop.Excel;
         public static bool Convert(string sourcePath, string targetPath, XlFixedFormatType targetType)
        {
        	 bool result;
        	 object missing = Type.Missing;
        	 Microsoft.Office.Interop.Excel.Application application = null;
        	 Workbook workBook = null;
        	 try
        	 {
        	     application = new Microsoft.Office.Interop.Excel.Application();
        	     object target = targetPath;
        	     object type = targetType;
        	     workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
        	         missing, missing, missing, missing, missing, missing, missing, missing, missing);
        	
        	     workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
        	     result = true;
        	 }
        	 catch
        	 {
        	     result = false;
        	 }
        	 finally
        	 {
        	     if (workBook != null)
        	     {
        	         workBook.Close(true, missing, missing);
        	         workBook = null;
        	     }
        	     if (application != null)
        	     {
        	         application.Quit();
        	         application = null;
        	     }
        	     GC.Collect();
        	     GC.WaitForPendingFinalizers();
        	     GC.Collect();
        	     GC.WaitForPendingFinalizers();
        	 }
        	 return result;
        }

     

    static void Main(string[] args)
      {
            string excelfilePath = ReadIni(@"c:\\file_important\\inicfg.ini", "INFO_R", "epath", "DefaultName");
            string pdffilePath = ReadIni(@"c:\\file_important\\inicfg.ini", "INFO_R", "ppath", "DefaultName");
    
           //  bool result = Program.Convert("C:\\report.xls", "C:\\测试报告", XlFixedFormatType.xlTypePDF);
            bool result = Program.Convert(excelfilePath, pdffilePath, XlFixedFormatType.xlTypePDF);
            //如果转换成功
            if (result)
            {
               
            }
    
        }
    点赞 1 评论 复制链接分享

相关推荐