excel有时候列数比较多,行数也比较多,转换成xps文档的时候,一般是通过打印来实现。

由于打印的范围限制,所以会出现本来在一行的数据,由于列数比较多,溢出范围,被打印到两页了。

为解决这个问题,需要设置一下sheet的缩放。

1.测试缩放在excel程序中:

在excel程序中有打印设置,如图(默认是无缩放的):

设置缩放(将所有列调整为一页),如图:

经过测试,这样设置后的打印效果,同一行的数据打印后在同一页了。

2.c#代码实现:

代码实现的方式是设置WorkSheet的PageSetup.FitToPagesTall属性。

测试代码如下:

  Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Type tp = app.GetType();
Microsoft.Office.Interop.Excel.Workbooks workBook = app.Workbooks;
Type elType = workBook.GetType();
object objelName = sourceFile;
Microsoft.Office.Interop.Excel.Workbook ebook = (Microsoft.Office.Interop.Excel.Workbook)elType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, workBook, new Object[] { objelName, true, true });
Object missing = System.Reflection.Missing.Value;
for (int i = ; i < ebook.Worksheets.Count; i++)
{
Worksheet ws = ebook.Worksheets[i + ];
ws.PageSetup.Orientation = XlPageOrientation.xlPortrait;//页面方向竖向
ws.PageSetup.Zoom = false;
ws.PageSetup.FitToPagesWide = ;
ws.PageSetup.FitToPagesTall = false;
}
ebook.PrintOut(missing, missing, missing, missing, missing, true, missing, xpsFile);
tp.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, app, null);
workBook.Close();
app.Quit();

经验证,可行。

感谢每一位阅读此篇文章的人,希望可以帮到你。

最新文章

  1. 如何保证ArrayList线程安全
  2. Unity arm64
  3. 错误:The Controls collection cannot be modified because the control contains code blocks (i.e. ). .
  4. [BZOJ3670][UOJ#5][NOI2014]动物园
  5. 【原创】pads2007 Layout 电气连接性检查过孔显示错误
  6. 枚举基类Enum详解
  7. iOS多线程系列(1)
  8. sql server 2008 学习笔记
  9. shell网络客户端
  10. iOS应用如何得知用户有新拍的图片?
  11. Swift基础之PickerView(时间)选择器
  12. Windows、Linux的环境变量
  13. @repository的含义,并且有时候却不用写,为什么?
  14. 【转】亲测plsql Developer配置免安装oralce客户端步骤
  15. 跨域请求设置withCredentials
  16. 18.解决合并androidmanfest错误
  17. css层叠性和继承性
  18. Py修行路 python基础 (二十二)异常处理
  19. getElementsByTagName 、 getElementsByName 、getElementById区别
  20. scrapy--BeautifulSoup

热门文章

  1. 1022: [SHOI2008]小约翰的游戏John【Nim博弈,新生必做的水题】
  2. a*b(mod m)的实现过程
  3. FSFS和VDFS存储方式的区别
  4. element-ui中upload组件如何传递文件及其他参数
  5. 基于Vue的页面切换左右滑动效果
  6. Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类
  7. es6重点笔记:let,const
  8. [one day one question] nodejs require 缓存,无法检测文件变化
  9. c#套料程序设计
  10. vuejs axios安装配置与使用