gdqq456gdq 2021-05-18 18:45 采纳率: 0%
浏览 171
已结题

CVI导出EXCEL中的图片

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

  • 写回答

1条回答 默认 最新

  • 小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)
            {
               
            }
    
        }
    评论

报告相同问题?

悬赏问题

  • ¥15 将两文件中相同行数行 打印至同一行
  • ¥15 关于#单片机#的问题:c51单片机想做个密码重置按键K13不知道如何去做,用了24c02来存储
  • ¥20 有没有会python的帮帮我😥
  • ¥15 如何修改系统里的设备信息及某某镇某某村如图所示
  • ¥15 变数的长度不一样”。是什么原因呢?如何修改?
  • ¥15 matlab作业不会写
  • ¥15 eclipse mqtt 消息消费问题
  • ¥15 vue2(标签-chrome|关键词-浏览器兼容)
  • ¥15 python网络流自动生成系统 医学领域
  • ¥15 sql查询仓库里都有什么