// 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(文件名)。打印())像打印文件的Excel C#
感謝幫助下這個附件我!
這是屏幕截圖錯誤 http://i.stack.imgur.com/Kg9Z8.png – Pshtiwan
我在問題中添加了該圖像,因爲它在那裏是必需的。不在評論中。對此的簡短回答是,您設置的寬度和高度是多少? –