您好我正在尝试将带有文本框和矩形对象的Excel文件转换为PDF文件,我尝试使用Spire.Xls但在转换XML错误时遇到错误然后当我尝试使用GemBox文本框和矩形不显示在PDF上时我累了Microsoft.Office.Interop.Excel没有正确转换提前谢谢
答案 0 :(得分:0)
对我来说,也可以转换文本框和三角形。
将它放在一个按钮上并通过引用为我工作:
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");
答案 1 :(得分:0)
您复制粘贴以下方法,
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”并选择属性,然后将“嵌入互操作类型”更改为false
您可以按以下方式调用该方法
ConvertToPDF(@"D:\WithImage_Shapes.xlsx", @"D:\WithImage_Shapes.pdf", XlFixedFormatType.xlTypePDF);
你可以得到你期望的结果。
如果我的回答满足了您的期望,请向上提示并点击绿色勾号。
答案 2 :(得分:0)