Home > Software engineering >  Excel operation problem
Excel operation problem

Time:09-26

The following continuous pasting the source data to many lines of code is what memory will always increase? There are ways to release the memory?
(not the whole Range of paste, must be such a one line)


For (long I=0; i <10000; I++)
{
//get purpose Range
TargetRange2. AttachDispatch (sheet. Get_Range (COleVariant (RowIndexNum), COleVariant (RowIndexNum)), TRUE);

//get the entire line
TargetRange2=TargetRange2. Get_EntireRow ();

//assignment
TargetRange2. Put_Value2 (testrange get_Value2 ());

//release
TargetRange2. ReleaseDispatch ();

//the next row
RowIndexNum++;
}

CodePudding user response:

TargetRange2. AttachDispatch (sheet. Get_Range (COleVariant (RowIndexNum), COleVariant (RowIndexNum)), TRUE);
TargetRange2 =TargetRange2. Get_EntireRow ();//here TargetRange2 has been change

Try adding a variable
 
//get purpose Range
TargetRange2. AttachDispatch (sheet. Get_Range (COleVariant (RowIndexNum), COleVariant (RowIndexNum)), TRUE);

//get the entire line
RangePtr TargetRange3=TargetRange2. Get_EntireRow ();

//assignment
TargetRange3. Put_Value2 (testrange get_Value2 ());

//release
TargetRange2. ReleaseDispatch ();

CodePudding user response:

reference 1st floor zgl7903 response:
TargetRange2. AttachDispatch (sheet. Get_Range (COleVariant (RowIndexNum), COleVariant (RowIndexNum)), TRUE);
TargetRange2 =TargetRange2. Get_EntireRow ();//here TargetRange2 has been change

Try adding a variable
 
//get purpose Range
TargetRange2. AttachDispatch (sheet. Get_Range (COleVariant (RowIndexNum), COleVariant (RowIndexNum)), TRUE);

//get the entire line
RangePtr TargetRange3=TargetRange2. Get_EntireRow ();

//assignment
TargetRange3. Put_Value2 (testrange get_Value2 ());

//release
TargetRange2. ReleaseDispatch ();



Is not this reason, the line commented out, just paste the first column, memory or increase quickly,
//get purpose Range
TargetRange2. AttachDispatch (sheet. Get_Range (COleVariant (RowIndexNum), COleVariant (RowIndexNum)), TRUE);

//get the entire line
.//RangePtr TargetRange3=TargetRange2 get_EntireRow ();

//assignment
TargetRange3. Put_Value2 (testrange get_Value2 ());

//release
TargetRange2. ReleaseDispatch ();
  • Related