我可以成功获取一个excel文件并将其导出为c#中的PDF文件
private static void ExportWorkbookToPDF(string workbook, string output)
{
if (string.IsNullOrEmpty(workbook) || string.IsNullOrEmpty(output))
{
throw new NullReferenceException("Cannot create PDF copy " +
"from empty workbook.");
}
Application excelApplication = new Application();
excelApplication.ScreenUpdating = false;
excelApplication.DisplayAlerts = false;
excelApplication.Visible = false;
Workbook excelWorkbook = excelApplication.Workbooks.Open(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
"\\" + workbook);
if (excelWorkbook == null)
{
excelApplication.Quit();
excelApplication = null;
excelWorkbook = null;
throw new NullReferenceException("Cannot create new excel workbook.");
}
try
{
excelWorkbook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF,
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
"\\" + output);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
finally
{
excelWorkbook.Close();
excelApplication.Quit();
excelApplication = null;
excelWorkbook = null;
}
}
为了将 excel 文件保存为页面宽度而不是页面高度,我需要访问哪些参数或对象?