Home > Software engineering >  The inside of the CRange put_Item how to use?
The inside of the CRange put_Item how to use?

Time:09-30

M_Rge. Put_Item (COleVariant ((long), 1), COleVariant ((long) 1, COleVariant ((" hello "));
Excel, A1 A1 the bar no value
I mainly want to put the interface and the database data export to excel, use cycle is tested under in this statement, but there is no value, before get_range sheet can be used to lose as a single, single is behind the seemingly can only write A1, A2, if can't use the I said to cycle
Check it on the website put_Item this way, but according to the first sentence that no hello output, consult!
By the way I am using ODBC

CodePudding user response:

Why don't you use SetItem?
M_ExlRge. SetItem (_variant_t (lItenIndex), _variant_t ((long), 1), _variant_t ((long) lRecordIndex));

CodePudding user response:

Top, LS said

CodePudding user response:

This does not seem to set_Item only put_Item

CodePudding user response:

We have CRange ODBC how?

 
# import "MSO9. DLL" rename (" RGB ", "RBGMSO") rename (" SearchPath ", "SearchPathMSO") \
Rename (" DocumentProperties DocumentPropertiesMSO ", "") no_auto_exclude
# import "VBE6EXT. OLB" no_namespace no_auto_exclude
# import "EXCEL9. OLB" rename (" RGB ", "RBGXL") rename (" DialogBox ", "DialogBoxXL") \
Rename (" used by CopyFile CopyFileXL ", "") rename (" ReplaceText", "ReplaceTextXL") rename (" IPicture ", "IPictureXL") \
Rename (" IFont IFontXL ", "") rename (" DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces no_auto_exclude



#include
#include

Void dump_com_error (_com_error & amp; E)
{
_tprintf (_T (" Oops - hit an error! \ n "));
_tprintf (_T (" \ \ a tCode=% 08 lx \ n "), e.E rror ());
_tprintf (_T (" \ \ a tCode fancy=% s \ n "), e.E rrorMessage ());
_bstr_t bstrSource (e.S ource ());
_bstr_t bstrDescription (e.D escription ());
_tprintf (_T (" \ \ a tSource=% s \ n "), (LPCTSTR) bstrSource);
_tprintf (_T (" \ \ a tDescription=% s \ n "), (LPCTSTR) bstrDescription);
}

//If this is placed in the scope of the smart Pointers, they must be
//explicitly Release (d) before CoUninitialize () is called. If any reference
//count is non - zero, a protection fault will occur.
Struct StartOle {
StartOle () {CoInitialize (NULL); }
~ StartOle () {CoUninitialize (); }
} _inst_StartOle;


Void main ()
{
Using the namespace Excel;

_ApplicationPtr pXL;

Try
{
PXL. CreateInstance (L "Excel. Application");

The pXL - & gt; The Visible=VARIANT_TRUE;

WorkbooksPtr pBooks=pXL - & gt; Workbooks.
_WorkbookPtr pBook=pBooks - & gt; Add ((long) xlWorksheet);

_WorksheetPtr pSheet=pXL - & gt; ActiveSheet.

Try {
//one will fail
PSheet - & gt; Name="Market Share?" ;
} the catch (_com_error & amp; E) {
Dump_com_error (e);
}

PSheet - & gt; Name="Market Share!" ;

PSheet - & gt; Range [" A2 "] - & gt; A "Value=" https://bbs.csdn.net/topics/Company;
PSheet - & gt; Range [" B2 "] - & gt; B Value="https://bbs.csdn.net/topics/Company";
PSheet - & gt; Range [" C2 "] - & gt; C Value="https://bbs.csdn.net/topics/Company";
PSheet - & gt; Range [" D2 "] - & gt; D Value="https://bbs.csdn.net/topics/Company";

PSheet - & gt; Range [" A3 "] - & gt; Value=https://bbs.csdn.net/topics/75.0;
PSheet - & gt; Range [" B3 "] - & gt; Value=https://bbs.csdn.net/topics/14.0;
PSheet - & gt; Range [" C3 "] - & gt; Value=https://bbs.csdn.net/topics/7.0;
PSheet - & gt; Range [" D3 "] - & gt; Value=https://bbs.csdn.net/topics/4.0;

Sleep(1000);

RangePtr pRange=pSheet - & gt; Range [A2: "D3"];
_ChartPtr pChart=pBook - & gt; Charts - & gt; The Add ();

PChart - & gt; PRange ChartWizard (Range (*), (long) xl3DPie, 7 l, (long) xlRows,
1 l, 0 l, 2 l, "Market Share");

Sleep (6000);

PBook - & gt; Saved=VARIANT_TRUE;
The pXL - & gt; The Quit ();
} the catch (_com_error & amp; E) {
Dump_com_error (e);
}
}

CodePudding user response:

reference 4 floor zgl7903 response:
CRange ODBC how have again?
[/code]

Right, use Crange, it was com call
 
M_books. AttachDispatch (m_app get_Workbooks ());
LpDisp=m_books. Open (filepath, covOptional, covOptional, covOptional, covOptional, covOptional,
CovOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional,
CovOptional, covOptional);
//get the workbook
M_book. AttachDispatch (lpDisp);
M_sheets. AttachDispatch (m_book get_Worksheets ());
LpDisp=m_sheets. Get_Item (COleVariant ((long), 1));
M_sheet. AttachDispatch (lpDisp);//open the corresponding sheet

For (I=0; I & lt; num; I + +)
{
M_range=m_sheet. Get_Cells ();
Info=vecInfo [I];
STR. The Format (_T (" %. 4 f "), the info. D_data);
M_range. Put_Item (COleVariant (long (I + 1)), COleVariant (long (1)), COleVariant (STR));
}

CodePudding user response:

https://wenku.baidu.com/view/d7383548767f5acfa1c7cd30.html
  • Related