Excel API Library for .NET - Sample Browser | Document Solutions | Set scale and resolution
[
フレーム]
Refer to the following example code to see how to set the scaling ratio and dpi of the exported image.
// Create a jpg file stream
FileStream outputStream = new FileStream("SetScaleAndResolution.jpg", FileMode.Create);
//create a new workbook
var workbook = new GrapeCity.Documents.Excel.Workbook();
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Range["B1"].Value = "Circle";
worksheet.Range["B1"].HorizontalAlignment = HorizontalAlignment.Center;
Drawing.IShape circle = worksheet.Shapes.AddShape(Drawing.AutoShapeType.Oval, 20, 20, 100, 100);
worksheet.Range["E1"].Value = "Square";
worksheet.Range["E1"].HorizontalAlignment = HorizontalAlignment.Center;
Drawing.IShape square = worksheet.Shapes.AddShape(Drawing.AutoShapeType.Rectangle, 165, 20, 100, 100);
circle.TextFrame.HorizontalAnchor = Drawing.HorizontalAnchor.Center;
circle.TextFrame.VerticalAnchor = Drawing.VerticalAnchor.AnchorMiddle;
square.TextFrame.HorizontalAnchor = Drawing.HorizontalAnchor.Center;
square.TextFrame.VerticalAnchor = Drawing.VerticalAnchor.AnchorMiddle;
Excel.ImageSaveOptions options = new Excel.ImageSaveOptions();
// Set the scaling of the exported image
options.ScaleX = 2.0;
options.ScaleY = 1.5;
// Set the dpi of the exported jpg file
options.Resolution = 192;
worksheet.ToImage(outputStream, Drawing.ImageType.JPG, options);
// Close the image stream
outputStream.Close();
' Create a jpg file stream
Dim outputStream = File.Create("SetScaleAndResolution.jpg")
' Create a new Workbook
Dim workbook As New Workbook
Dim worksheet As IWorksheet = workbook.Worksheets(0)
worksheet.Range("B1").Value = "Circle"
worksheet.Range("B1").HorizontalAlignment = HorizontalAlignment.Center
Dim circle As Drawing.IShape = worksheet.Shapes.AddShape(Drawing.AutoShapeType.Oval, 20, 20, 100, 100)
worksheet.Range("E1").Value = "Square"
worksheet.Range("E1").HorizontalAlignment = HorizontalAlignment.Center
Dim square As Drawing.IShape = worksheet.Shapes.AddShape(Drawing.AutoShapeType.Rectangle, 165, 20, 100, 100)
circle.TextFrame.HorizontalAnchor = Drawing.HorizontalAnchor.Center
circle.TextFrame.VerticalAnchor = Drawing.VerticalAnchor.AnchorMiddle
square.TextFrame.HorizontalAnchor = Drawing.HorizontalAnchor.Center
square.TextFrame.VerticalAnchor = Drawing.VerticalAnchor.AnchorMiddle
' Set the scaling and dpi of the exported jpg image file
Dim options As New Excel.ImageSaveOptions With {
.ScaleX = 2.0,
.ScaleY = 1.5,
.Resolution = 192
}
worksheet.ToImage(outputStream, Drawing.ImageType.JPG, options)
' close the image stream
outputStream.Close()