您好,我试图转换我的文本框和矩形对象的Excel文件到PDF文件,我试图使用Spire.Xls,但在转换过程中遇到错误XML错误,然后当我尝试GemBox文本框和矩形不显示在PDF上,然后当我累了Microsoft.Office.Interop.Excel没有正确转换,提前感谢
发布于 2018-05-15 17:03:04
您尝试过了吗?文件另存为另存为类型(在下拉列表中向下)和*.pdf
对我来说,这也转换了文本框和三角形。
把它放在一个单独的按钮上,对我的引用工作:
using Excel = Microsoft.Office.Interop.Excel
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"H:\My Documents\Fun\tri.xlsx");
xlWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, @"H:\My Documents\Fun\tri.pdf");发布于 2018-05-15 19:08:17
你复制粘贴下面的方法,
private bool ConvertToPDF(string sourcePath, string targetPath, XlFixedFormatType targetType)
{
bool result;
object missing = Type.Missing;
ApplicationClass application = null;
Workbook workBook = null;
try
{
application = new ApplicationClass();
object target = targetPath;
object type = targetType;
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
workBook = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}将引用添加为"Microsoft.Office.Interop.Excel“,添加后,右键单击"Microsoft.Office.Interop.Excel”并选择属性,将"Embed Interop Types“更改为false
您可以像下面这样调用该方法
ConvertToPDF(@"D:\WithImage_Shapes.xlsx", @"D:\WithImage_Shapes.pdf", XlFixedFormatType.xlTypePDF);你可以得到你所期望的结果。
如果我的答案符合您的期望,请向上填写答案,然后单击绿色的勾号。
发布于 2018-05-16 11:27:13
我尝试过Spire.XLS,但它转换成功了吗?我的代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"aa.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.SaveToPdf("ToPDF.pdf");PDF文件:

https://stackoverflow.com/questions/50346090
复制相似问题