Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / File Operations / Saving Data to a File / Saving to an Image File
In This Topic
    Saving to an Image File
    In This Topic

    You can save data in an image file by creating a bitmap instance using the SheetView.SaveImage class method. This method saves all the data in the specified cell range in an image.

    Users can provide parameters such as row, column, rowcount, colcount, height, and width. A Bitmap instance is returned as output and it represents the image of the range.

    The bitmap instance can be saved to an image file by using the Save method. It can also be utilized in the following ways:

    The following GIF illustrates saving a cell range to an image file.

    Create images in Spread for Winforms

    The following code example shows how to create an image using cell ranges in a worksheet and save the image instance in an image format.

    C#
    Copy Code
    // Make sure that fpSpread1.LegacyBehaviors does not contain LegacyBehaviors.Style
    fpSpread1.Features.EnhancedShapeEngine = true;
    
    fpSpread1.Sheets[0].Cells[0, 0].Text = "Spread";
    fpSpread1.Sheets[0].Cells[0, 1].Text = "For";
    fpSpread1.Sheets[0].Cells[0, 2].Text = "Winforms";
    fpSpread1.BorderCollapse = FarPoint.Win.Spread.BorderCollapse.Enhanced;
                
    var bitmap = fpSpread1.ActiveSheet.SaveImage(0, 0, 3, 3);
    bitmap.Save("D:\\sample\\Img.png", System.Drawing.Imaging.ImageFormat.Png);
    
    Visual Basic
    Copy Code
    ' Make sure that fpSpread1.LegacyBehaviors does Not contain LegacyBehaviors.Style
    FpSpread1.Features.EnhancedShapeEngine = True
    
    FpSpread1.Sheets(0).Cells(0, 0).Text = "Spread"
    FpSpread1.Sheets(0).Cells(0, 1).Text = "For"
    FpSpread1.Sheets(0).Cells(0, 2).Text = "Winforms"
    FpSpread1.BorderCollapse = FarPoint.Win.Spread.BorderCollapse.Enhanced
    
    Dim bitmap = FpSpread1.ActiveSheet.SaveImage(0, 0, 3, 3)
    bitmap.Save("D:\sample\Img.png", Imaging.ImageFormat.Png)