彩票走势图

如何使用Aspose.Cells删除工作表转换为图片的空白处

原创|其它|编辑:郝浩|2012-11-20 13:37:16.000|阅读 1480 次

概述:使用Aspose.Cells将工作表转换成图片时,可以通过几行简单的代码,就可以在图像输出之前删除工作表中的空白以及边框。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

我们在生成Excel工作表时,往往会产生一些没有数据的空白单元格,如果直接转换成图片的话,图片中就会存在一大片空白的地方,这样产看数据就会不方便。使用Aspose.Cells将工作表转换成图片时,可以通过几行简单的代码,就可以在图像输出之前删除工作表中的空白以及边框。

[C#]

//Instantiate a workbook
//Open the template file
Workbook book = new Workbook(@"e:\test\MyTestBook1.xls");

//Get the first worksheet
Worksheet sheet = book.Worksheets[0];

//Specify your print area if you want
//sheet.PageSetup.PrintArea = "A1:H8";

//To remove the white border around the image.
sheet.PageSetup.LeftMargin = 0;
sheet.PageSetup.RightMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.TopMargin = 0;

//Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Emf;
//Set only one page would be rendered for the image
imgOptions.OnePagePerSheet = true;
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

//Create the SheetRender object based on the sheet with its
//ImageOrPrintOptions attributes
SheetRender sr = new SheetRender(sheet, imgOptions);
//Convert the image
sr.ToImage(0, "e:\\test\\img_MyTestBook1.emf");
 

VB

'Instantiate a workbook
'Open the template file
Dim book As New Workbook("e:\test\MyTestBook1.xls")

'Get the first worksheet
Dim sheet As Worksheet = book.Worksheets(0)

'Specify your print area if you want
'sheet.PageSetup.PrintArea = "A1:H8";

'To remove the white border around the image.
sheet.PageSetup.LeftMargin = 0
sheet.PageSetup.RightMargin = 0
sheet.PageSetup.BottomMargin = 0
sheet.PageSetup.TopMargin = 0

'Define ImageOrPrintOptions
Dim imgOptions As New ImageOrPrintOptions()
imgOptions.ImageFormat = ImageFormat.Emf
'Set only one page would be rendered for the image
imgOptions.OnePagePerSheet = True
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank

'Create the SheetRender object based on the sheet with its
'ImageOrPrintOptions attributes
Dim sr As New SheetRender(sheet, imgOptions)
'Convert the image
sr.ToImage(0, "e:\test\img_MyTestBook1.emf")


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP