// 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
我在问题中添加了该图像,因为它在那里是必需的。不在评论中。对此的简短回答是,您设置的宽度和高度是多少? –