Experience in developing Office programs in C + + Builder 6 (ii)

Source: Internet
Author: User

(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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.