在 C# 中打开或保存 Excel 时,我需要传递文件名 ref 而不是给出字符串(完整路径)。下面是一个代码片段
object fileName = (string)e.Argument;
object oMissing = System.Reflection.Missing.Value;
if (fileName.ToString().EndsWith("xlsx"))
{
Excel.Workbook wb;
object oMissing1 = Type.Missing;
var app = new Microsoft.Office.Interop.Excel.Application();
wb = app.Workbooks.Open(@"C:\Users\273714\Desktop\ProoferReport1.xlsx",
oMissing1, oMissing1, oMissing1, oMissing1,
oMissing1, oMissing1, oMissing1, oMissing1,
oMissing1, oMissing1, oMissing1, oMissing1,
oMissing1, oMissing1);
wb.SaveAs(@"C:\Users\273714\Desktop\Proofer Report2.xls",
Excel.XlFileFormat.xlExcel8, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Excel.XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
app.Quit();
app.Quit();
}
如果是word文档,我可以像这样打开它
oDoc = oWord.Documents.Open(ref fileName, ref oMissing,
ref readOnly, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref isVisible, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
我也需要在 Excel 中使用文件名的相同方式。任何帮助将不胜感激。