We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Range Excel to jpg

Hello, I have a strange problem with “Convert a Range to jpg”, I have the following code:

Workbook oWorkbook = new Workbook(“C:\BORRAR\Libro1.xls”);
Aspose.Cells.Range oRango = oWorkbook.Worksheets.GetRangeByName(“TABLA”);
        Worksheet oHoja = oRango.Worksheet;

        oHoja.PageSetup.LeftMargin = 0;
        oHoja.PageSetup.RightMargin = 0;
        oHoja.PageSetup.TopMargin = 0;
        oHoja.PageSetup.BottomMargin = 0;
        oHoja.AutoFitColumns();
        oHoja.AutoFitRows();

        oHoja.Cells.InsertColumn(oRango.ColumnCount + oRango.FirstColumn);
        oHoja.Cells.SetColumnWidth(oRango.ColumnCount + oRango.FirstColumn, 0.15);
        oHoja.PageSetup.PrintArea = CellsHelper.CellIndexToName(oRango.FirstRow, oRango.FirstColumn) + ":" + CellsHelper.CellIndexToName(oRango.FirstRow + oRango.RowCount - 1, oRango.FirstColumn + oRango.ColumnCount);

        ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
        imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
        imgOptions.OnePagePerSheet = true;
     
        SheetRender sr = new SheetRender(oHoja, imgOptions);
        sr.ToImage(0, @"C:\BORRAR\Prueba.jpg");
        System.Diagnostics.Process.Start(@"C:\BORRAR\Prueba.jpg");</font></font></span></div><div><span style="background-color: rgb(255, 255, 255); line-height: 24px; white-space: pre-wrap;"><font color="#212121"><font size="2"><br></font></font></span></div><div><font size="2"><span style="background-color: rgb(255, 255, 255); line-height: 24px; white-space: pre-wrap;"><font color="#212121">At new application works perfectly (prueba.jpg) , but when I insert this code into my big application with the <b>same varibles</b> </font></span><span style="color: rgb(33, 33, 33); font-family: inherit; line-height: 24px; white-space: pre-wrap; background-color: rgb(255, 255, 255);">does not work well </span><span style="color: rgb(33, 33, 33); line-height: 24px; white-space: pre-wrap; background-color: rgb(255, 255, 255);">(prueba2.jpg). </span></font></div><div><font size="2"><span style="color: rgb(33, 33, 33); line-height: 24px; white-space: pre-wrap; background-color: rgb(255, 255, 255);">Anyone idea? </span></font></div><div><font size="2"><span style="color: rgb(33, 33, 33); line-height: 24px; white-space: pre-wrap; background-color: rgb(255, 255, 255);">Thank you a lot.</span></font></div><div><span style="background-color: rgb(255, 255, 255); line-height: 24px; white-space: pre-wrap;"><font color="#212121"><font size="2"><br></font></font></span></div>

Hi Yolanda,

Thanks for your posting and using Aspose.Cells.

Please download and try the latest version:
Aspose.Cells
for .NET v8.3.1.4
and see if it makes any difference.

Please make sure Calibri font is installed on your machine where you are running your application.

Are you getting this problem in one application and not in another application provided both applications are running on same machine? Or are they running on different machines?

Hi thank you for reply,
Im using the last version of aspose cell with license and both application are running in the same machine.
I tested in other machine and also fails, and i have Calibri font installed.

I dont Know what to do!
SheetRender uses a variable windows or regional settings of the machine or something?

Thank you so much

Hi,

Thanks for your posting and using Aspose.Cells.

Please try this code and let us know your feedback. I have commented the following lines to see if it makes any difference at your end.

oHoja.Cells.InsertColumn(oRango.ColumnCount + oRango.FirstColumn);
oHoja.Cells.SetColumnWidth(oRango.ColumnCount + oRango.FirstColumn, 0.15);

If your problem still occurs, then provide us your console application project replicating this issue. We will look into it and help you asap.

C#

Workbook oWorkbook = new Workbook(“Libro1.xls”);
Aspose.Cells.Range oRango = oWorkbook.Worksheets.GetRangeByName(“TABLA”);
Worksheet oHoja = oRango.Worksheet;
oHoja.PageSetup.LeftMargin = 0;
oHoja.PageSetup.RightMargin = 0;
oHoja.PageSetup.TopMargin = 0;
oHoja.PageSetup.BottomMargin = 0;
oHoja.AutoFitColumns();
oHoja.AutoFitRows();
//oHoja.Cells.InsertColumn(oRango.ColumnCount + oRango.FirstColumn);
//oHoja.Cells.SetColumnWidth(oRango.ColumnCount + oRango.FirstColumn, 0.15);
oHoja.PageSetup.PrintArea = CellsHelper.CellIndexToName(oRango.FirstRow, oRango.FirstColumn) + “:” + CellsHelper.CellIndexToName(oRango.FirstRow + oRango.RowCount - 1, oRango.FirstColumn + oRango.ColumnCount);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
imgOptions.OnePagePerSheet = true;
SheetRender sr = new SheetRender(oHoja, imgOptions);
sr.ToImage(0, @“Prueba.jpg”);