// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
string filename = dlg.FileName;
xpsFilePath = System.Environment.CurrentDirectory + "\\" + dlg.SafeFileName + ".xps";
SourceUrl.Text = filename;
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
ExcelFile.Load(filename).Print();
}
var convertResults = OfficeToXps.ConvertToXps(SourceUrl.Text, ref xpsFilePath);
switch (convertResults.Result)
{
case ConversionResult.OK:
xpsDoc = new System.Windows.Xps.Packaging.XpsDocument(xpsFilePath, FileAccess.ReadWrite);
documentViewer1.Document = xpsDoc.GetFixedDocumentSequence();
officeFileOpen_Status = true;
break;
case ConversionResult.InvalidFilePath:
// Handle bad file path or file missing
break;
case ConversionResult.UnexpectedError:
// This should only happen if the code is modified poorly
break;
case ConversionResult.ErrorUnableToInitializeOfficeApp:
// Handle Office 2007 (Word | Excel | PowerPoint) not installed
break;
case ConversionResult.ErrorUnableToOpenOfficeFile:
// Handle source file being locked or invalid permissions
break;
case ConversionResult.ErrorUnableToAccessOfficeInterop:
// Handle Office 2007 (Word | Excel | PowerPoint) not installed
break;
case ConversionResult.ErrorUnableToExportToXps:
// Handle Microsoft Save As PDF or XPS Add-In missing for 2007
break;
}
我正在尝试打印Excel 文件但出现此错误( system.argumentexception 宽度和高度在此行中必须为非负数( ExcelFile.Load(filename).Print()),如下面的附件
谢谢你的帮助!