通过Process.Start类调用电子表格 [英] Call Spreadsheet by Process.Start Class

查看:139
本文介绍了通过Process.Start类调用电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我同时拥有Office和OpenOffice。

我通过EXCEL.EXE调用Excel使用System.process.Start

现在我想要检查我的系统是否没有Ms Office然后它应该调用电子表格。



.xls是我的文件扩展名。

I am having both Ms Office and OpenOffice.
I have Called Excel by "EXCEL.EXE" by using System.process.Start
and now I want to Check if My system doesnot have Ms Office then it should call Spreadsheet.

.xls is my file extension.

推荐答案

你可以通过多种方式检查是否安装了ms excel。

我的方式是



Various way you can check that ms excel is installed or not.
I way is

public bool IsMsExcelInstalled(){
   RegistryKey key = Registry.ClassesRoot;
   RegistryKey excelKey = key.OpenSubKey("Excel.Application");
   return excelKey == null ? false : true;
}





另一种方式





Another way

public bool IsMsExcelInstalled(){
  Type excel = Type.GetTypeFromProgID("Excel.Application");
  return excel !=null;
}





根据安装的MS Excel,您现在可以决定是否开设办公室。



Based on MS Excel installed you now can take decision to run open office.

如果excel没有instaled,那么我想你想存储/下载该文件。如果是那么

if excel not instaled then i guess you want to store/download that file. If so then
if (!IsMsExcelInstalled()){
 //assume fileFullName will be the file path which need to store/download.
  var fileInfo = new FileInfo(fileFullName);
            string fileName = Path.GetFileName(fileFullName);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
            HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            HttpContext.Current.Response.ContentType = "application/octet-stream";
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.WriteFile(fileFullName);
            HttpContext.Current.Response.End();
}





您要下载其他文件类型然后需要更改



You you want to download other file types then you need to change the value of

HttpContext.Current.Response.ContentType

属性。例如,如果你下载pdf文件,那么值将是

property. for example if you download pdf file then the value will be

HttpContect.Current.Response.ContentType="Application/Pdf"

如果是doc文件,则

值为Application / msword。

If it is doc file then
value will be "Application/msword".


这篇关于通过Process.Start类调用电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆