Home > Software engineering >  Consult the MFC operation of the Excel file, how to find the location of the tag name?
Consult the MFC operation of the Excel file, how to find the location of the tag name?

Time:09-16

 
The range=sheet. Get_Range (COleVariant (_mark), covOptional);


If only one sheet, I can find the location of the label corresponding with the above statements, the tag name _mark,

But now I'm Excel have more than one sheet, I don't know _mark is inside the sheet a few,
If I direct
 
The range of=sheet1. Get_Range (COleVariant (_mark), covOptional);

_mark is not in sheet1, will jump went wrong at this moment, so I don't know how to traverse the find,

What I want is: according to the label name _mark find its location in the multiple sheet, consult everybody a great god what to do? Thank you for

CodePudding user response:

 SheetsPtr m_pSheets=pWorkbook - & gt; Worksheets. 
For (long iSheet=1; ISheet{
_WorksheetPtr pSheet=m_pSheets - & gt; The GetItem (iSheet);
PSheet - & gt; Activate ();

Try
{
RangePtr pRange=pSheet - & gt; The Range of [_mark];
If (pRange)
{
}
}
The catch (_com_error & amp; E)
{
}
}



CodePudding user response:

refer to the second floor zgl7903 response:
 SheetsPtr m_pSheets=pWorkbook - & gt; Worksheets. 
For (long iSheet=1; ISheet{
_WorksheetPtr pSheet=m_pSheets - & gt; The GetItem (iSheet);
PSheet - & gt; Activate ();

Try
{
RangePtr pRange=pSheet - & gt; The Range of [_mark];
If (pRange)
{
}
}
The catch (_com_error & amp; E)
{
}
}


Bosses, I didn't find the SheetsPtr in types of garage, _WorksheetPtr, RangePtr those types, such as with Excel installed version?
 
CFont0 ft;
CApplication1 app1.
CWorkbooks books;
CWorkbook book;
CWorksheets sheets;
CWorksheet sheet;
CRange range;
LPDISPATCH lpDisp;
COleVariant vResult;//COleVariant class is the encapsulation of the VARIANT structure
COleVariant covOptional ((long) DISP_E_PARAMNOTFOUND VT_ERROR);

//get the Workbook
Book. AttachDispatch (lpDisp);
//get the Worksheets
Sheets. AttachDispatch (book. Get_Worksheets ());
//sheet=sheets. Get_Item (COleVariant ((short) 1));
//get the current active sheet
//if a cell is in edit status, this operation can't return, will have been waiting for
LpDisp=book. Get_ActiveSheet ();
Sheet. AttachDispatch (lpDisp);


This is my now,

CodePudding user response:

refer to the second floor zgl7903 response:
 SheetsPtr m_pSheets=pWorkbook - & gt; Worksheets. 
For (long iSheet=1; ISheet{
_WorksheetPtr pSheet=m_pSheets - & gt; The GetItem (iSheet);
PSheet - & gt; Activate ();

Try
{
RangePtr pRange=pSheet - & gt; The Range of [_mark];
If (pRange)
{
}
}
The catch (_com_error & amp; E)
{
}
}


I excel is 2007 before, and then I downloaded 2010 mount, add or no SheetsPtr, type a repository _WorksheetPtr, RangePtr these a few, how to do excuse me?

CodePudding user response:

refer to the second floor zgl7903 response:
 SheetsPtr m_pSheets=pWorkbook - & gt; Worksheets. 
For (long iSheet=1; ISheet{
_WorksheetPtr pSheet=m_pSheets - & gt; The GetItem (iSheet);
PSheet - & gt; Activate ();

Try
{
RangePtr pRange=pSheet - & gt; The Range of [_mark];
If (pRange)
{
}
}
The catch (_com_error & amp; E)
{
}
}



Refer to the
https://blog.csdn.net/lzwxyz/article/details/6676988
https://www.cnblogs.com/lishennan/p/4583913.html
https://www.cnblogs.com/spriteflk/p/4344756.html
https://blog.csdn.net/weixin_34277853/article/details/94078196
https://blog.csdn.net/bagboy_taobao_com/article/details/46521555

Done SheetsPtr _WorksheetPtr, RangePtr problem,

But RangePtr pRange=pSheet - & gt; The Range of [_mark]; This code is problematic?
Range function is
 
RangePtr Range [] [];
__declspec (property (get=GetOnSheetDeactivate, put=PutOnSheetDeactivate))
_bstr_t OnSheetDeactivate [];
__declspec (property (get=GetEnableFormatConditionsCalculation, put=PutEnableFormatConditionsCalculation))

I tried the along while have no, who help me to look at. Thanks

CodePudding user response:

SheetsPtr CWorksheets is similar with you, one is an import way into class libraries, a derived class library is the wizard generated
VS the reference example

 
//Copyright (c) Microsoft Corporation. All rights reserved.
//
//This source code is only intended as a supplement to the
//Microsoft Visual c + + Language Reference and related
//electronic documentation provided with Microsoft Visual c + +.
//See these sources for detailed information regarding the
//Microsoft Visual c + + product.

//NOTE: This example will only work with Excel10 OfficeXP in
//the Compile with cl/GX comexcel. CPP
# include "stdafx. H"


# define an 1
# define OFFICEXP 2
# define OFFICE2000 3

//the Default Settings
# define OFFICE_VER an
# define USE_PROGID 1
# define USE_LIBID 0

# # define _M2STR (x) x
# define M2STR _M2STR (x) (x)


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related