(iv) Operation of cells
The operation of a cell is actually an action on a range (range). The general code snippet is as follows:
RangePtr r;
r=EWS4->get_Range(V("a1"), V("a1"));
r->set_Value(V("Species No"));
Therefore, the operation of the contents of the cell is actually the first to get a range of operations (range), and then set_value the process.
It is not difficult to connect to the database. It is not difficult to write the data in the database to Excel worksheet, it is to traverse the dataset, then write the corresponding field to the corresponding cell, so I don't discuss it in detail here. The same is true for the input of formulas.
The effect of the actual operation is shown below:
Here are two places to explain. The first is the font and column width adjustment. The specific code is as follows:
r=EWS4->get_Range(V(CellRef), V(CellRef2));
r->Font->set_Name(V("Arial"));
r->get_Columns()->AutoFit();
r->set_WrapText(V(true));
The operation process is also to select a range, and then set the font name, column width, automatic line change and so on.
The second is the display of graphics. This requires a few more actions to:
void __fastcall TMainForm::FillDataBtnClick(TObject *Sender)
{
unsigned int DataHandle;
HPALETTE APalette;
unsigned short MyFormat;
Graphics::TBitmap *Bitmap = new Graphics::TBitmap();
... ...
while (!Table1->Eof)
{
... ...
CellRef="e"+IntToStr(Count);
r=EWS4->get_Range(V(CellRef), V(CellRef));
Bitmap->Assign(Table1Graphic);
Bitmap->SaveToClipboardFormat(MyFormat,DataHandle,APalette);
Clipboard()->SetAsHandle(MyFormat,DataHandle);
EWS4->Paste(V(LPDISPATCH(r)), TNP, 0);
... ...
}
... ...
delete Bitmap;
return;
}
This takes the Bitmap->assign, takes the contents of the Graphics field as bitmap, and then saves bitmap to the Datahandle in the Clipboard format and returns the saved format to MyFormat. The contents of Datahandle are then "copied" to the Clipboard in MyFormat format, using the Clipbboard Setashandle method. Finally, use the worksheet paste method to copy the picture on the Clipboard to the place specified by R.
Note that r simply indicates the position of the upper-left corner of the copied content. For a picture, it doesn't and should not automatically fit into a cell. Therefore, in the above example, the width of column E can not automatically adapt to the width of the picture, need to be adjusted separately.