How to convert Excel to PNG using C#

Hi,


We tried to convert the excel file to PNG.

Following is our sample code

ImageSaveOptions imageSaveOptions = new ImageSaveOptions();
imageSaveOptions.OutputType = OutputType.String;
imageSaveOptions.ConvertFileType = ImageSaveOptions.ImageFileType.Png;
imageSaveOptions.UsePdf = true;

var conversionDocumentPath = conversionHandler.Convert(fileName, imageSaveOptions);

Sample Files:
File1.xlsx: 1 sheet, 3000 rows
File2.xlsx: 6 sheet, print area = 14 pages.

Once we set the option “UsePdf” = true.

File1.xlsx: only can be converted to 1 png file. But missed some content.
File2.xlsx: only can be converted the sheet 1(4 pages), sheet 2(2 pages). missed sheet 3/4/5/6

Once we set the option “UsePdf” = false.
File1.xlsx: only can be converted to 1 png file. Includes all contents but it blur.
File2.xlsx: only can be converted to 6 png files. Includes all sheets and all contents but it blur.


In fact, we have tried to converted the excel to png with different way. but no way can make us convert the excel file to png completely.

Please advise. Thank you a lot. It’s a key point to decide purchase this tools OR NOT.

Hello,


Thank you for giving a try to GroupDocs.Conversion API.

Sorry to hear that you are facing such issues, we have successfully re-produced the issues and notified to product team for solution, once we have any update from product team we will inform you here.

Thank you for your patience.

Warm Regards,

The issues you have found earlier (filed as CONVERSIONNET-889) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by groupdocs.notifier.

Hi,


We tried to convert the excel files to JPEG format via live demo and SDK.

Please extract the enclosed file for your reference.

If we convert the files by live demo. the content is more clear than converted by SDK.

Could you help clarify they are using the same library or not?

If yes, could you provide some sample code to us for reference. Thank you a lot!

Hi ,

Thank you for sharing details. Live demo site is using different library and GroupDocs.Conversion 3.x.x are Next Generation API which is UI less so you can use it in any application.
Regarding image quality you can specify the image quality by setting image DPI property

//
ImageSaveOptions

new ImageSaveOptions { ConvertFileType = ImageFileType.Jpg,
OutputType = OutputType.String, Dpi = 1600 }

//

If you will need any help or you
will have any other questions please feel free to ask.



Warm Regards

Hi,

Have you tested the code which you recommand for us?

ImageSaveOptions

new ImageSaveOptions { ConvertFileType = ImageFileType.Jpg,
OutputType = OutputType.String, Dpi = 1600 }


I have tested it. and set the dpi as 1600. But I checked the converted file property. the dpi value still is 96. Could you help us check this?


thank you!


Hi,

Sorry for the inconvenience


ImageSaveOptions is our standard classes to specify the image related properties that should work, it has Dpi property and also have another property related to image quality which is JpegQuality with default value is 100 both effect the image quality as per image output type.


But now we can see in this release its not working properly, we have notified this issue to product team for solution, once we have any update from product team we will update you here.


Thank you for your patience.


Warm Regards,

Hi,


Could you provide a target date for the fix?

@beary.hu,

We’d recommend you to migrate to GroupDocs.Conversion for .NET 20.4. Please have a look at the migration notes. API provides a lot of properties when converting a source file (e.g. Excel) to image file format, such as:

  • Image resolution
  • Grayscale
  • Contrast
  • Brightness

Have a look at this documentation article and below code snippet:

string outputFileTemplate = Path.Combine("c:\output", "converted-page-{0}.png");
SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
using (Converter converter = new Converter("sample.xlsx"))
{
    ImageConvertOptions options = new ImageConvertOptions
    {
        Format = ImageFileType.Png,
        FlipMode = ImageFlipModes.FlipY,
        Brightness = 50,
        Contrast = 50,
        Gamma = 0.5F,
        Grayscale = true,
        HorizontalResolution = 300,
        VerticalResolution = 100
    };
     
    converter.Convert(getPageStream, options);
}