Spread 8.0 Documentation
Example
Support Options

Glossary Item Box

Example


The following example loads a picture in a picture cell from a resource. The user can click a button to save the picture to a buffer and load it into another cell.

C++

BOOL COCXpropertiesDlg::OnInitDialog()

{

m_Spread.SetCol(1);

m_Spread.SetRow(1);

// Create a picture cell type

m_Spread.SetCellType(9);

HINSTANCE h = AfxGetResourceHandle();

// Load the picture

m_Spread.SetTypePictPicture( m_Spread.LoadResPicture((long)h, "IDB_BITMAP1", "BITMAP", 1));

or

CString s;

s.Format(_T("#%d"), MAKEINTRESOURCE(IDB_BITMAP1));

m_Spread.SetTypePictPicture( m_Spread.LoadResPicture((long)h, (LPCTSTR)s, "BITMAP", 1).m_lpDispatch);

}

void COCXpropertiesDlg::OnClickFpbtn1()

{

    CPicture picture;

    VARIANT buffer;

    VARIANT size;

    m_Spread.SetCol(1);

    m_Spread.SetRow(1);

    picture = m_Spread.GetTypePictPicture();

    // Save picture to buffer

    m_Spread.SavePictureBuffer((IDispatch *)picture.m_lpDispatch, 1, &buffer, &size);

    m_Spread.SetCol(2);

    m_Spread.SetRow(1);

    // Create a picture cell type

    m_Spread.SetCellType(9);

    // Load picture from buffer

    m_Spread.SetTypePictPicture(m_Spread.LoadPictureBuffer(&buffer, &size, 1));

    // Use SysFreeString to free the buffer

    SysFreeString(buffer.bstrVal);

}

Visual Basic

Private Sub Form_Load()
    ' Create a picture cell type
    fpSpread1.Sheet = 1
    fpSpread1.Col = 1
    fpSpread1.Row = 1
    fpSpread1.CellType = CellTypePicture
    ' Load a resource into the cell
    ' Resource created using the resource editor
    ' Create EXE to see loaded resource
    fpSpread1.TypePictPicture = fpSpread1.LoadResPicture(App.hInstance, "flower", "custom", PictureTypeJPEG)
    fpSpread1.ColWidth(1) = 75
    fpSpread1.RowHeight(1) = 200
End Sub

Private Sub Command1_Click()
    Dim buffer
    Dim size
    fpSpread1.Sheet = 1
    fpSpread1.Col = 1
    fpSpread1.Row = 1
    ' Save picture from cell
    fpSpread1.SavePictureBuffer fpSpread1.TypePictPicture, PictureTypeJPEG, buffer, size
    fpSpread1.Col = 1
    fpSpread1.Row = 2
    fpSpread1.CellType = CellTypePicture
    ' Load picture in another cell
    fpSpread1.TypePictPicture = fpSpread1.LoadPictureBuffer(buffer, size, PictureTypeJPEG)
    MsgBox size
End Sub

Private Sub Form_Resize()
    fpSpread1.Height = ScaleHeight - 1400
    fpSpread1.Width = ScaleWidth
End Sub

Copyright © GrapeCity, inc. All rights reserved.