原創|其它|編輯:郝浩|2012-11-20 13:37:16.000|閱讀 1511 次
概述:使用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@fc6vip.cn
文章轉載自:慧都控件網