Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue May 27, 2025 1:29 pm

Hi;

I am using Spire.XLS for .NET in ASP.NET 9 MVC application

In the documentation, I found a page that explains how to capture a high-resolution image from a cell range.

The ResetResolution method uses specific Windows libraries to control the resolution. I'm trying to achieve the same method but in a cross-platform way.

For example, using AnyBitmap from IronSoftware, I could implement low-resolution capture on Linux with the following code:
Code: Select all
AnyBitmap image = sheet.ToImage(cellRange.Row, cellRange.Column, cellRange.LastRow, cellRange.LastColumn);
var content = image.ExportBytes(AnyBitmap.ImageFormat.Png);
result.Add(content);


Do you know of any way to use the ResetResolution method in a way that is compatible with Linux?

Best regards

ccarballo
 
Posts: 4
Joined: Tue Mar 14, 2023 5:51 pm

Wed May 28, 2025 10:12 am

Hello,

Thanks for your inquiry.
Please refer to the following code to set the image resolution when converting. If you have any other questions later, please contact us in time.
Code: Select all
//Get worksheet
Worksheet worksheet = wb.Worksheets[0];
//Set DPI
wb.ConverterSetting.XDpi = 300;
wb.ConverterSetting.YDpi = 300;
Stream stream=worksheet.ToImage(1, 1, 10, 10);

Sincerely,
Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Wed May 28, 2025 11:12 am

Perfect, it greatly simplifies my workflow. If I want to paste that image into a Word document while preserving the original dimensions captured from Excel, I should then apply this conversion. Is correct or id there a better way?

Code: Select all
private Telerik.Documents.Primitives.Size GetScaledImageSizeForDocument(MemoryStream stream)
{
    using var image = AnyBitmap.FromStream(stream);
    double scaleFactor = WORD_DPI / IMAGE_DPI;
    double width = image.Width * scaleFactor;
    double height = image.Height * scaleFactor;
    return new Telerik.Documents.Primitives.Size(width, height);
}

ccarballo
 
Posts: 4
Joined: Tue Mar 14, 2023 5:51 pm

Thu May 29, 2025 9:53 am

Hello,

Thank you for your feedback.
We provide the Spire.Doc for .NET (Spire.Doc Pack(hot fix) Version:13.5.11), which supports inserting images into Word document while preserving their original dimensions. Reference code example:
Code: Select all
Document doc = new Document();
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();
DocPicture picture = paragraph.AppendPicture(stream);
picture.Width = finalWidth;
picture.Height = finalHeight;
doc.SaveToFile(outputPath , Spire.Doc.FileFormat.Docx);

If you have any other questions, please feel free to write back. Thank you in advance.

Sincerely,
Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Return to Spire.XLS

cron