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.

Mon Apr 16, 2018 6:23 pm

Is there a way to adjust the size of the image during the conversion ? I'm seeing a big reduction in image size. I'm using the sample code used on your site.
Using 7.12

Code: Select all
namespace Xls2Image

{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\test.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToImage("sample.jpg");
        }
    }

}


efiallo
 
Posts: 2
Joined: Fri Apr 06, 2018 3:54 pm

Tue Apr 17, 2018 3:45 am

Hello,

Thank you for contacting us.
Sorry there is no directly way to adjust image size during conversion. You can change the image size via Image class (Here is the online details ) or improve the image size by setting resolution (such as below sample code). Welcome to get it back if your have any question.
Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
MemoryStream stream=new MemoryStream();
sheet.ToEMFStream(stream, 1, 1, sheet.LastRow, sheet.LastColumn);
Image imageFile = Image.FromStream(stream);
//Set resolution
Bitmap images = ResetResolution(imageFile as Metafile, 300);
images.Save("Result.png", ImageFormat.Png);
private Bitmap ResetResolution(Metafile mf, float resolution)
{
     int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
     int height = (int)(mf.Height * resolution / mf.VerticalResolution);
     Bitmap bmp = new Bitmap(width, height);
     bmp.SetResolution(resolution, resolution);
     Graphics g = Graphics.FromImage(bmp);
     g.DrawImage(mf, 0, 0);
     g.Dispose();
     return bmp;
}

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Tue Apr 17, 2018 2:59 pm

Thanks Nina, I don't see that my version of Spire XLS has an definition for ToEMFStream , I'm using 7.12.

efiallo
 
Posts: 2
Joined: Fri Apr 06, 2018 3:54 pm

Wed Apr 18, 2018 2:20 am

Hello,

Thanks for your feedback.
It's strange, I can find the ToEMFStream method in the Spire.Xls 7.12 ( Spire.Xls.dll 7.12.0.6040). Do you use the Free Spire.Office 2.15 which contains the Spire.Xls.dll 7.12.14 but doesn't include ToEMFStream definition? For your case, please upgrade to a newer version to test again :Spire.XLS Pack(Hotfix) Version:8.4.6 or Spire.Office Platinum (DLL Only) Version:2.16.27.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Fri Apr 20, 2018 8:33 am

Hello,

Greetings from E-iceblue.
How is your issue now?
Thanks for your valuable feedback and time.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1182
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.XLS