Long iSheetCount=sheets. Get_Count ();
The range=range. Get_Rows ();
Long iRow=range. Get_Row ();
//long iRow=range. Get_Count ();
The range=range. The get_Columns ();
//long iColumn=range. Get_Column ();
Long iColumn=range. Get_Count ();
Obtain the EXCEL table there is something wrong with the value of the current row and column
Access lines
The range=range. Get_Rows ();
Long iRow=range. Get_Row ();
Long iRow=range. Get_Count ();
No data in the table, the two are 1 don't get to zero, the number of rows of data, access is 1
Get columns
Long iColumn=range. Get_Column (); Always get is 1
Long iColumn=range. Get_Count (); This access is normal
Want to ask, what is the problem, why always can't get lines
CodePudding user response:
https://download.csdn.net/download/yeah2000/3576494reference
CodePudding user response:
//Excel14. CPP: Defines the entry point for the console application.
//
# include "stdafx. H"
#include
#include
# import "C:/Program Files/Common Files/Microsoft Shared/13th/the oledata.mso. DLL" \
Rename (" RGB ", "RBGMSO") rename (" SearchPath ", "SearchPathMSO") \
Rename (" DocumentProperties DocumentPropertiesMSO ", "") no_auto_exclude
# import "C:/Program Files/Common Files/Microsoft Shared/VBA/VBA6/VBE6EXT OLB" no_namespace
# import "C:/Program Files/Microsoft Office/13th/excel. Exe" \
Rename (" IFont IFontXL ", ""),
Rename (" DialogBox ExcelDialogBox ", "") rename (" RGB", "ExcelRGB") \
Rename (" used by CopyFile ExcelCopyFile ", "") rename (" ReplaceText", "ExcelReplaceText") \
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);
}
Struct StartOle {
StartOle () {CoInitialize (NULL); }
~ StartOle () {CoUninitialize (); }
} _inst_StartOle;
Int main (int arg c, char * argv [])
{
Using the namespace Office;
Using the namespace Excel;
_ApplicationPtr pXL;
Try
{
PXL. CreateInstance (L "Excel. Application");
The pXL - & gt; PutVisible (0, VARIANT_TRUE);
WorkbooksPtr pBooks=pXL - & gt; Workbooks.
_WorkbookPtr pBook=pBooks - & gt; Add ((long) xlWorksheet);
_WorksheetPtr pSheet=pXL - & gt; ActiveSheet.
//modify the name
Try
{
//one will fail
PSheet - & gt; Name="Market Share?" ;
}
The catch (_com_error & amp; E)
{
Dump_com_error (e);
}
PSheet - & gt; Name="Market Share!" ;
//read/write data
{
PSheet - & gt; Range [" A2 "] - & gt; Value2="Company A";
_bstr_t bStr=pSheet - & gt; Range [" A2 "] - & gt; Value2.
_tprintf (_T (A2 \ ""="% s \ n"), (LPCTSTR) bStr);
}
//insert hyperlink
Try
{
//Range (" i2). Select
//ActiveSheet. Hyperlinks. Add Anchor:=Selection, Address:=_
//"http://bbs.csdn.net/topics/392326155", TextToDisplay:="test hyperlink
"
RangePtr pRang=pSheet - & gt; Range [" i2];
HyperlinksPtr pLinks=pSheet - & gt; Hyperlinks.
PLinks - & gt; Add (pRang,
"Http://bbs.csdn.net/topics/392375991",
VtMissing,
VtMissing,
"Test links");
}
The catch (_com_error & amp; E)
{
Dump_com_error (e);
}
//insert picture
Try
{
Excel: : ShapesPtr pShapes=pSheet - & gt; Shapes;
RangePtr range=pSheet - & gt; Range [H1: O10 "];
Float l=range - & gt; Left, t=range - & gt; Top;
Float w=range - & gt; Width, h=range - & gt; Height;
Excel: : ShapePtr pShape=pShapes - & gt; AddPicture (_bstr_t (" C: \ \ tt. JPG "),
MsoFalse msoTrue, l, t, w, h);
}
The catch (_com_error & amp; E)
{
Dump_com_error (e);
}
//insert the pie chart
Try
{
PSheet - & gt; Range [" A2 "] - & gt; Value2="Company A";
PSheet - & gt; Range [" B2 "] - & gt; Value2="Company B".
PSheet - & gt; Range [" C2 "] - & gt; Value2="Company C";
PSheet - & gt; Range [" D2 "] - & gt; Value2="Company D";
PSheet - & gt; Range [" A3 "] - & gt; Value2=75.0;
PSheet - & gt; Range [" B3 "] - & gt; Value2=14.0;
PSheet - & gt; Range [" C3 "] - & gt; Value2=7.0;
PSheet - & gt; Range [" D3 "] - & gt; Value2=4.0;
PSheet - & gt; Range [" A4 "] - & gt; Value2=75.0;
PSheet - & gt; Range [" B4 "] - & gt; Value2=14.0;
PSheet - & gt; Range [" C4 "] - & gt; Value2=7.0;
PSheet - & gt; Range [" D4 "] - & gt; Value2=4.0;
RangePtr pRange=pSheet - & gt; Range [A2: "D3"];
_ChartPtr pChart=pBook - & gt; Charts - & gt; The Add ();
PChart - & gt; PRange ChartWizard (Range (*), (long) Office: : xl3DPie, 7 l, (long) Office: : xlRows,
1 l, 0 l, 2 l, "Market Share");
}
The catch (_com_error & amp; E)
{
Dump_com_error (e);
}
//Settings page format
Try
{
PageSetupPtr pPageSet=pSheet - & gt; PageSetup;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull