如何使用c#以只读方式创建excel文件 [英] How to make an excel file readonly using c#
本文介绍了如何使用c#以只读方式创建excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,我能够生成一个.xls文件,但是我无法将其作为只读文件。
我在'var fileName ...'行收到错误,说明'你是缺少using指令或汇编引用'。
In the following code I am able to generate an .xls file but am unable to make it as readonly.
I get an error at line 'var fileName..' stating that 'are you missing an using directive or assembly reference' .
ExcelApp.ActiveWorkbook.SaveCopyAs("C:\\Users\\RAJENDRAN\\Desktop\\DailySoresOutwardIndent.xls");
ExcelApp.ActiveWorkbook.Saved = true;
var fileInfo = new fileInfo("C:\\Users\\RAJENDRAN\\Desktop\\DailySoresOutwardIndent.xls");
fileInfo.IsReadOnly = true;
推荐答案
试试这个
try this
System.IO.FileInfo objFileInfo = new System.IO.FileInfo(szFilePath);
objFileInfo.IsReadOnly = true;
这篇关于如何使用c#以只读方式创建excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文