exportasfixedformat没有纸张大小

时间:2014-02-07 01:40:26

标签: c# excel pdf

我正在尝试将C#excel文件中的exportasfixedformat导出为pdf文件。但转换为pdf文件(列和行)纸张大小时,excel文件太大。将excel文件导出为pdf文件时,有没有办法消除纸张尺寸?

ws.UsedRange.Font.Size = 5;
ws.UsedRange.Font.Name = "Arial Narrow";

ws.UsedRange.Columns.ColumnWidth = 20;

Range RS;
RS = ws.get_Range("A:A", Type.Missing);
RS.EntireColumn.ColumnWidth = 30;

ws.PageSetup.Zoom =false;
ws.PageSetup.FitToPagesWide = 1;
ws.PageSetup.FitToPagesTall = false;

ws.PageSetup.Orientation = 
    Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
ws.PageSetup.PaperSize = 
    Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperLegal;
ws.PageSetup.LeftMargin = 0.5;
ws.PageSetup.RightMargin = 0.5;
ws.PageSetup.TopMargin = 0.5;
ws.PageSetup.BottomMargin = 0.5;

ws.ExportAsFixedFormat(
    Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, Filename,
       Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityMinimum, 
    true, false, 1, ws.UsedRange.Count, false, System.Reflection.Missing.Value);

但是这段代码的输出会产生相互重叠的字母,这使得它们不可读。

1 个答案:

答案 0 :(得分:0)

在调用导出函数之前,您应该设置FitToPagesTall或FitToPagesWide。

ws.PageSetup.Orientation = 
      Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;

// Zoom property must be false, otherwise the "FitToPages" properties 
// are ignored.
ws.PageSetup.Zoom = false;

// these set the number of pages tall or wide the worksheet will be 
// scaled to when printed.
ws.PageSetup.FitToPagesTall = 1;
ws.PageSetup.FitToPagesWide = 1;