vb.net 我正在尝试将 excel 文件导出为 pdf,但对齐失败了?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15216280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Im trying to export an excel file to pdf but alignment is going off?
提问by Goku Fds
When exporting the sheet the alignment goes off. half data goes on next line. How can i alignment the sheet programmatically and convert it to pdf without alignment going off.
导出工作表时,对齐会关闭。一半数据在下一行。如何以编程方式对齐工作表并将其转换为 pdf 而不对齐。
I need something like fit to page.
我需要适合页面的东西。
回答by Taotao
The width of PDF depend on you Excel print setting, at default, it will set to A4 portrait, so the export PDF will leave the half data to next line; if you set the paper size to A3 Landscape, then export to PDF, it will show the correct format.
PDF的宽度取决于您的Excel打印设置,默认情况下会设置为A4纵向,因此导出PDF会将一半的数据保留到下一行;如果您将纸张大小设置为 A3 Landscape,然后导出为 PDF,它将显示正确的格式。
回答by chenz101
i have experienced same problem, so what i did:
我遇到了同样的问题,所以我做了什么:
for the excel file sheet i set the following
xlWorkbook = xlApps.Workbooks.Add(missing); xlWorkSheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); xlApps.ActiveWindow.View = Excel.XlWindowView.xlPageLayoutView; //pagelayout view xlWorkSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperA4; //set paper to A4 xlWorkSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlPortrait; //set to portrait //margins 'Narrow' xlWorkSheet.PageSetup.LeftMargin = 0.65; //55 xlWorkSheet.PageSetup.RightMargin = 0.25; xlWorkSheet.PageSetup.BottomMargin = 0.75; xlWorkSheet.PageSetup.TopMargin = 0.75; //60 xlWorkSheet.PageSetup.HeaderMargin = 0;convert my excel file and scale the size. (just change 120 to fit your document)
//here is the scaling Worksheet xlmsheet = excelWorkBook.Sheets[1]; xlmsheet.PageSetup.Zoom = 120; // Save it in the target format. if (excelWorkBook != null) excelWorkBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, paramExportFilePath, XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing, Type.Missing, false, paramMissing);
对于excel文件表,我设置了以下内容
xlWorkbook = xlApps.Workbooks.Add(missing); xlWorkSheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); xlApps.ActiveWindow.View = Excel.XlWindowView.xlPageLayoutView; //pagelayout view xlWorkSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperA4; //set paper to A4 xlWorkSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlPortrait; //set to portrait //margins 'Narrow' xlWorkSheet.PageSetup.LeftMargin = 0.65; //55 xlWorkSheet.PageSetup.RightMargin = 0.25; xlWorkSheet.PageSetup.BottomMargin = 0.75; xlWorkSheet.PageSetup.TopMargin = 0.75; //60 xlWorkSheet.PageSetup.HeaderMargin = 0;转换我的excel文件并缩放大小。(只需更改 120 以适合您的文档)
//here is the scaling Worksheet xlmsheet = excelWorkBook.Sheets[1]; xlmsheet.PageSetup.Zoom = 120; // Save it in the target format. if (excelWorkBook != null) excelWorkBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, paramExportFilePath, XlFixedFormatQuality.xlQualityStandard, true, true, Type.Missing, Type.Missing, false, paramMissing);
回答by D_Bester
Why not just use FitToPagesWide and FitToPagesTall
为什么不直接使用 FitToPagesWide 和 FitToPagesTall
xlWorkSheet.PageSetup.Zoom = False
xlWorkSheet.PageSetup.FitToPagesWide = 1
xlWorkSheet.PageSetup.FitToPagesTall = 1

