C++ OLE automation - how do I format the borders?

L

Lucas Coppio

Hi, ive done a small program using OLE automation but I still don't
know how to put borders on some cells
This is the MACRO code, but I need to translate it to something the VC+
+/OLE2 can understand, but I have no clue on how to do that.

Sub Macro1()
'
' Macro1 Macro
'

'
Range("B10:I50").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
 
L

Lynn McGuire

Hi, ive done a small program using OLE automation but I still don't
know how to put borders on some cells
This is the MACRO code, but I need to translate it to something the VC+
+/OLE2 can understand, but I have no clue on how to do that.

Sub Macro1()
'
' Macro1 Macro
'

'
Range("B10:I50").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub

Here is a full C++ OLE Automation interface for Excel:

http://groups.google.com/group/micr...8&q=excel+c+++ole+automation#69eb7ded92ab5d93

Lynn
 
L

Lucas Coppio

Here is a full C++ OLE Automation interface for Excel:

http://groups.google.com/group/microsoft.public.excel/browse_thread/t...

Lynn

Thank you Lynn, I'll give it a deep look later (i'm copying the codes
right now to a new project and will try to compile a test program
later).
But unfortunatelly this is a little urgent and I don't have much able
time to learn everything of such a complex code, I have a program that
generates a datasheet in XLS using the OLE automation, but I have to
add borders to a big table and it proves to be quite hard to me right
now mainly because I'm not usued to do codes for computers (I'm a
firmware developer for microcontrolers and embed devices).

I'm basically using the example that is in msdn about OLE automation
(automation without using MFC and #import), so its basically:

HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp,
LPOLESTR ptName, int cArgs...) {
....
}

and things like this in the main()

// Get ActiveSheet object
IDispatch *pXlSheet;
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlApp, L"ActiveSheet",
0);
pXlSheet = result.pdispVal;
}

the program is working fine right now, except by the borders that I
need in the ranges:

Range("B10:I50").Select
Range("B60:I100").Select
Range("B110:I150").Select
Range("B160:I200").Select

in anyway, I will understand if you don't want to code it for me or to
point where I may find it in the code you just showed me.
 
L

Lynn McGuire

Thank you Lynn, I'll give it a deep look later (i'm copying the codes
right now to a new project and will try to compile a test program
later).
But unfortunatelly this is a little urgent and I don't have much able
time to learn everything of such a complex code, I have a program that
generates a datasheet in XLS using the OLE automation, but I have to
add borders to a big table and it proves to be quite hard to me right
now mainly because I'm not usued to do codes for computers (I'm a
firmware developer for microcontrolers and embed devices).

I'm basically using the example that is in msdn about OLE automation
(automation without using MFC and #import), so its basically:

HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp,
LPOLESTR ptName, int cArgs...) {
...
}

and things like this in the main()

// Get ActiveSheet object
IDispatch *pXlSheet;
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result, pXlApp, L"ActiveSheet",
0);
pXlSheet = result.pdispVal;
}

the program is working fine right now, except by the borders that I
need in the ranges:

Range("B10:I50").Select
Range("B60:I100").Select
Range("B110:I150").Select
Range("B160:I200").Select

in anyway, I will understand if you don't want to code it for me or to
point where I may find it in the code you just showed me.

That is the problem. There is a LOT of coding items that you have
to handle in order to initialize the interface. This is basically
the sequence of events:
// fm2n_old.cpp
// The OLE Automation interface to Excel is mostly written using:
// "How to automate Excel from C++ without using MFC or #import"
// http://support.microsoft.com/kb/216686

// to call this code :
// if (ConnectToNotebook (notebook, RunInTestMode, true))
// {
// // do your excel data transfer here
// DisconnectFromNotebook (RunInTestMode);
// }

// see getCellInfo or putCellInfo for single cell data transfer examples

// see PutRowInTable for bulk transfer example, note that the more data can
// be transferred at one time, the faster the data transfer is

For formatting a range, see the functions:
int setRangeFont (std::string rangeValue, std::string fontNameValue, int boldValue, int sizeValue, int colorValue);
int SetRangeWidthAlignment (std::string rangeValue, int columnWidthValue, int horizontalAlignmentValue);

The C++ OLE automation interface for Excel (or any other OLE server)
is very involved.

Lynn
 
L

Lucas Coppio

That is the problem.  There is a LOT of coding items that you have
to handle in order to initialize the interface.  This is basically
the sequence of events:

 > // fm2n_old.cpp

 > // The OLE Automation interface to Excel is mostly written using:
 > // "How to automate Excel from C++ without using MFC or #import"
 > //http://support.microsoft.com/kb/216686

//  to call this code :
//              if (ConnectToNotebook (notebook, RunInTestMode, true))
//              {
//                      //  do your excel data transfer here
//                      DisconnectFromNotebook (RunInTestMode);
//              }

//  see getCellInfo or putCellInfo for single cell data transfer examples

//  see PutRowInTable for bulk transfer example, note that the more data can
//      be transferred at one time, the faster the data transfer is

For formatting a range, see the functions:
    int setRangeFont (std::string rangeValue, std::string fontNameValue, int boldValue, int sizeValue, int colorValue);
    int SetRangeWidthAlignment (std::string rangeValue, int columnWidthValue, int horizontalAlignmentValue);

The C++ OLE automation interface for Excel (or any other OLE server)
is very involved.

Lynn

I tried to make a simple main with the Connect to Notebook, but when I
compile I receive those errors.

Error 1 error C2065: 'MaxItemsInRow' : undeclared identifier e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.h
32
Error 2 error C2065: 'MaxLineChunks' : undeclared identifier e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.h
38
Error 4 error C2664: 'FindFirstFileW' : cannot convert parameter 1
from 'const char *' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 137
Error 3 error C2664: 'GetModuleFileNameW' : cannot convert parameter 2
from 'char [4096]' to 'LPWCH' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 117
Error 7 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'char [2000]' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 210
Error 8 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'char [2000]' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 231
Error 9 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'char [2000]' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 274
Error 5 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'const char *' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 154
Error 6 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'const char *' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 176
Error 12 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'const char *' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 496
Error 10 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'const char [25]' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 305
Error 11 error C2664: 'MessageBoxW' : cannot convert parameter 2 from
'const char [44]' to 'LPCWSTR' e:\users\user\documents\visual studio
2008\projects\xlscpp\xlscpp\fm2n_old.cpp 328
Error 13 error C3861: 'SetUnitsCase': identifier not found e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp
1851
Error 14 error C3861: 'SetUnitsCase': identifier not found e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp
1864
Error 15 error C3861: 'SetUnitsCase': identifier not found e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp
1879
 
L

Lucas Coppio

That is the problem.  There is a LOT of coding items that you have
to handle in order to initialize the interface.  This is basically
the sequence of events:

 > // fm2n_old.cpp

 > // The OLE Automation interface to Excel is mostly written using:
 > // "How to automate Excel from C++ without using MFC or #import"
 > //http://support.microsoft.com/kb/216686

//  to call this code :
//              if (ConnectToNotebook (notebook, RunInTestMode, true))
//              {
//                      //  do your excel data transfer here
//                      DisconnectFromNotebook (RunInTestMode);
//              }

//  see getCellInfo or putCellInfo for single cell data transfer examples

//  see PutRowInTable for bulk transfer example, note that the more data can
//      be transferred at one time, the faster the data transfer is

For formatting a range, see the functions:
    int setRangeFont (std::string rangeValue, std::string fontNameValue, int boldValue, int sizeValue, int colorValue);
    int SetRangeWidthAlignment (std::string rangeValue, int columnWidthValue, int horizontalAlignmentValue);

The C++ OLE automation interface for Excel (or any other OLE server)
is very involved.

Lynn

I solved most of the erros, but I still experience the following
errors

Error 1 error C2065: 'MaxItemsInRow' : undeclared identifier e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.h
32
Error 2 error C2065: 'MaxLineChunks' : undeclared identifier e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.h
38
Error 3 error C3861: 'SetUnitsCase': identifier not found e:\users\user
\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp 1851
Error 4 error C3861: 'SetUnitsCase': identifier not found e:\users\user
\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp 1864
Error 5 error C3861: 'SetUnitsCase': identifier not found e:\users\user
\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp 1879
 
L

Lynn McGuire

I solved most of the erros, but I still experience the following
errors

Error 1 error C2065: 'MaxItemsInRow' : undeclared identifier e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.h
32
Error 2 error C2065: 'MaxLineChunks' : undeclared identifier e:\users
\user\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.h
38
Error 3 error C3861: 'SetUnitsCase': identifier not found e:\users\user
\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp 1851
Error 4 error C3861: 'SetUnitsCase': identifier not found e:\users\user
\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp 1864
Error 5 error C3861: 'SetUnitsCase': identifier not found e:\users\user
\documents\visual studio 2008\projects\xlscpp\xlscpp\fm2n_old.cpp 1879

BTW, I am still using Visual Studio 2005 so this code is not VSVC 2008
tested.

MaxItemsInRow is an internal item that you should be able to get rid of.

MaxLineChunks is 20.

SetUnitsCase is an internal item that you should be able to replace with

std::string SetUnitsCase (std::string str)
{
return str;
}

Lynn
 
L

Lucas Coppio

BTW, I am still using Visual Studio 2005 so this code is not VSVC 2008
tested.

MaxItemsInRow is an internal item that you should be able to get rid of.

MaxLineChunks is 20.

SetUnitsCase is an internal item that you should be able to replace with

std::string SetUnitsCase (std::string str)
{
    return str;

}

Lynn

yes I managed that, but now I'm receiving an error from my linker :\

Error 1 error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > notebook" (?notebook@@3V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@A) XlsCpp.obj
 
L

Lucas Coppio

BTW, I am still using Visual Studio 2005 so this code is not VSVC 2008
tested.

MaxItemsInRow is an internal item that you should be able to get rid of.

MaxLineChunks is 20.

SetUnitsCase is an internal item that you should be able to replace with

std::string SetUnitsCase (std::string str)
{
    return str;

}

Lynn

yes I managed that, but now I'm receiving an error from my linker :\

Error 1 error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > notebook" (?notebook@@3V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@A) XlsCpp.obj
 
L

Lynn McGuire

BTW, I am still using Visual Studio 2005 so this code is not VSVC 2008
tested.

MaxItemsInRow is an internal item that you should be able to get rid of.

MaxLineChunks is 20.

SetUnitsCase is an internal item that you should be able to replace with

std::string SetUnitsCase (std::string str)
{
return str;

}

Lynn

yes I managed that, but now I'm receiving an error from my linker :\

Error 1 error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > notebook" (?notebook@@3V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@A) XlsCpp.obj

===================================================

Just create a std::string notebook global variable.

Man, my posted code was not clean !

Lynn
 
L

Lucas Coppio

yes I managed that, but now I'm receiving an error from my linker :\

Error 1 error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > notebook" (?notebook@@3V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@A) XlsCpp.obj

===================================================

Just create a std::string notebook global variable.

Man, my posted code was not clean !

Lynn

well, it happens alot when other people try to compile your codes,
sometimes its a library that differs, other times is the version of
the compiler...

About this "setRangeWidth...", does it set the borders also? I'm
reading it and I just cannot comprehend how it can do something
besides "changing the width of the cel", or does it change the width
of the cell's borders?
 
L

Lucas Coppio

yes I managed that, but now I'm receiving an error from my linker :\

Error 1 error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > notebook" (?notebook@@3V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@A) XlsCpp.obj

===================================================

Just create a std::string notebook global variable.

Man, my posted code was not clean !

Lynn

well, I entered the std::string notebook in my XlsCpp.cpp, it looks
like this right now

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <comdef.h>

#include "ole2.h"

#include <ctype.h>
#include <shellapi.h>
#include "asstring.h"
#include "fm2n_old.h"
#include "globalStr.h"

std::string notebook;

int main(int argc, char* argv[])
{
if (ConnectToNotebook (notebook, RunInTestMode, true))
{

DisconnectFromNotebook (RunInTestMode);
}
return 0;
}

It compiles, but when I run the code it gives an error in this part of
the code

// strip the suffix from the notebook prefix,
can be .xls or .xlsx
int len5 = g_notebookPrefix.size ();
g_notebookPrefix.erase (len5 - 4);
len5 = g_notebookPrefix.size();
if (g_notebookPrefix [len5 - 1] == '.') // THIS IS THE
LINE where the error happens!
g_notebookPrefix.erase (len5 - 1);

I removed this line part of the function, I also removed some parts of
the function that gets the directory (I turned it into a constant) but
the program keeps giving errors in different parts, now the last one
is an error message with alot of chinese characters...

If you can help me explaining this particular part of the code so I
can implement it in my own code I guess it would be faster

int SetRangeWidthAlignment (std::string rangeValue, int
columnWidthValue, int horizontalAlignmentValue)
{

VARIANT result;
VariantInit ( &result);
VARIANT range;
VariantInit ( &range);
range.vt = VT_BSTR;
_bstr_t address = _bstr_t (rangeValue.c_str ()); //must set
the range here!
range.bstrVal = address;
std::string errorMsg = "Select a range in the active
spreadsheet," + rangeValue + " (SetRangeWidthAlignment)";
AutoWrap(DISPATCH_PROPERTYGET, &result, pExcelSheet, L"Range",
errorMsg, 1, range);
//(DISPATCH_PROPERTYGET, & result1, pExcelSheet, L"Range",
errorMsg, 1, range);
if (result.vt == VT_DISPATCH)
{
if (columnWidthValue > 0)
{
VARIANT result2;
VariantInit ( & result2);
VARIANT columnWidth;
VariantInit ( & columnWidth); //columnWidth =
1
columnWidth.vt = VT_I4;
columnWidth.intVal = columnWidthValue;
std::string errorMsg = "Set the column width
of the selected cell," + rangeValue + " (SetRangeWidthAlignment)";
OLEMethod (DISPATCH_PROPERTYPUT, & result2,
result1.pdispVal, L"ColumnWidth", errorMsg, 1, columnWidth);
int res2 = result2.vt;
}
if (horizontalAlignmentValue != 0)
{


// var xlSolid = 1;
// int xlCenter = -4108;
// var xlBottom = -4107;
// var xlTop = -4160;
// var xlRight = -4152;
// var xlLeft = -4131;

// Excel Constants
// var xlCellTypeLastCell = 11;
// var xlThin = 2;
// var xlNone = -4142;
// var xlContinuous = 1;
// var xlThin = 2;
// var xlAutomatic = -4105;
// var xlExpression = 2;
VARIANT result5;
VariantInit ( & result5);
VARIANT horizontalAlignment;
VariantInit ( & horizontalAlignment);
horizontalAlignment.vt = VT_I4;
horizontalAlignment.intVal =
horizontalAlignmentValue;
std::string errorMsg = "Set horizontal
alingment of the selected range," + rangeValue +
" (SetRangeWidthAlignment)";
OLEMethod (DISPATCH_PROPERTYPUT, & result5,
result1.pdispVal, L"HorizontalAlignment", errorMsg, 1,
horizontalAlignment);
int res5 = result5.vt;
}
result1.pdispVal -> Release ();
}




I have to set the borders in my table, but as I see here it does
something with the alignment of the text and change the cell width?
thats it?

what should I do then to adapt it for my needs? I'm trying to adapt
this code comparing with the ones I have in here but Im totally dummy
when it comes to the OLEMethod(.....) .
 
L

Lynn McGuire

yes I managed that, but now I'm receiving an error from my linker :\

Error 1 error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > notebook" (?notebook@@3V?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@A) XlsCpp.obj

===================================================

Just create a std::string notebook global variable.

Man, my posted code was not clean !

Lynn

well, I entered the std::string notebook in my XlsCpp.cpp, it looks
like this right now

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include<comdef.h>

#include "ole2.h"

#include<ctype.h>
#include<shellapi.h>
#include "asstring.h"
#include "fm2n_old.h"
#include "globalStr.h"

std::string notebook;

int main(int argc, char* argv[])
{
if (ConnectToNotebook (notebook, RunInTestMode, true))
{

DisconnectFromNotebook (RunInTestMode);
}
return 0;
}

It compiles, but when I run the code it gives an error in this part of
the code

// strip the suffix from the notebook prefix,
can be .xls or .xlsx
int len5 = g_notebookPrefix.size ();
g_notebookPrefix.erase (len5 - 4);
len5 = g_notebookPrefix.size();
if (g_notebookPrefix [len5 - 1] == '.') // THIS IS THE
LINE where the error happens!
g_notebookPrefix.erase (len5 - 1);

I removed this line part of the function, I also removed some parts of
the function that gets the directory (I turned it into a constant) but
the program keeps giving errors in different parts, now the last one
is an error message with alot of chinese characters...

If you can help me explaining this particular part of the code so I
can implement it in my own code I guess it would be faster

int SetRangeWidthAlignment (std::string rangeValue, int
columnWidthValue, int horizontalAlignmentValue)
{

VARIANT result;
VariantInit (&result);
VARIANT range;
VariantInit (&range);
range.vt = VT_BSTR;
_bstr_t address = _bstr_t (rangeValue.c_str ()); //must set
the range here!
range.bstrVal = address;
std::string errorMsg = "Select a range in the active
spreadsheet," + rangeValue + " (SetRangeWidthAlignment)";
AutoWrap(DISPATCH_PROPERTYGET,&result, pExcelSheet, L"Range",
errorMsg, 1, range);
//(DISPATCH_PROPERTYGET,& result1, pExcelSheet, L"Range",
errorMsg, 1, range);
if (result.vt == VT_DISPATCH)
{
if (columnWidthValue> 0)
{
VARIANT result2;
VariantInit (& result2);
VARIANT columnWidth;
VariantInit (& columnWidth); //columnWidth =
1
columnWidth.vt = VT_I4;
columnWidth.intVal = columnWidthValue;
std::string errorMsg = "Set the column width
of the selected cell," + rangeValue + " (SetRangeWidthAlignment)";
OLEMethod (DISPATCH_PROPERTYPUT,& result2,
result1.pdispVal, L"ColumnWidth", errorMsg, 1, columnWidth);
int res2 = result2.vt;
}
if (horizontalAlignmentValue != 0)
{


// var xlSolid = 1;
// int xlCenter = -4108;
// var xlBottom = -4107;
// var xlTop = -4160;
// var xlRight = -4152;
// var xlLeft = -4131;

// Excel Constants
// var xlCellTypeLastCell = 11;
// var xlThin = 2;
// var xlNone = -4142;
// var xlContinuous = 1;
// var xlThin = 2;
// var xlAutomatic = -4105;
// var xlExpression = 2;
VARIANT result5;
VariantInit (& result5);
VARIANT horizontalAlignment;
VariantInit (& horizontalAlignment);
horizontalAlignment.vt = VT_I4;
horizontalAlignment.intVal =
horizontalAlignmentValue;
std::string errorMsg = "Set horizontal
alingment of the selected range," + rangeValue +
" (SetRangeWidthAlignment)";
OLEMethod (DISPATCH_PROPERTYPUT,& result5,
result1.pdispVal, L"HorizontalAlignment", errorMsg, 1,
horizontalAlignment);
int res5 = result5.vt;
}
result1.pdispVal -> Release ();
}




I have to set the borders in my table, but as I see here it does
something with the alignment of the text and change the cell width?
thats it?

what should I do then to adapt it for my needs? I'm trying to adapt
this code comparing with the ones I have in here but Im totally dummy
when it comes to the OLEMethod(.....) .

You need to give the notebook variable a name, i.e. "c:\\myspreadsheet.xls".

On setting your borders, you will need to record the macro
code and create the equivalent C++ code. It will be easy
once you have figured it out.

Lynn
 
L

Lucas Coppio

On 1/19/2011 10:54 AM, Lucas Coppio wrote:

You need to give the notebook variable a name, i.e.  "c:\\myspreadsheet..xls".

On setting your borders, you will need to record the macro
code and create the equivalent C++ code.  It will be easy
once you have figured it out.

Lynn

I've found some things about the code of the OLE setting borders in
cells in this topic
http://businessintelligence.ittoolb...rio-l/ole-excel-formatting-cell-border-587789

With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic

I know that the xlEdgeBottom constant = 9...but I don't know how to
reference it.
Currently, I'm double underlining the cell value with Font setting:
objCells.Item(2, lne).Font.Underline = -4119; // Double Underline

and the other said that he could get over it using this code

oRange.Borders.Item(9).Weight =3D 2 // =3D xlThin;
where oRange is a cell range object (or single cell).

But it looks nothing like the codes I'm doing with the OLE method.

but anyway, I'm trying to do something like that, but the I don't know
how to declare this oRange, every kind of declaration I tried returned
these errors

//THE CODE


771> IDispatch *pXlRange;
772 > {
773 > VARIANT parm;
774 > parm.vt = VT_BSTR;
775 > parm.bstrVal = ::SysAllocString(L"A10:J50");
776 >
777 > VARIANT result;
778 > VariantInit(&result);
779 > AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range",
1, parm);
780 > VariantClear(&parm);
781 >
782 > pXlRange = result.pdispVal;
783 > }
784 > pXlRange.Borders.Item(9).Weight = 3D;
785 >

Error 25 error C2059: syntax error : 'bad suffix on number' e:\users
\user\documents\visual studio 2008\projects\xlcpp\xlcpp\xlcpp.cpp 784
Error 27 error C2065: 'D' : undeclared identifier e:\users\user
\documents\visual studio 2008\projects\xlcpp\xlcpp\xlcpp.cpp 784
Error 26 error C2146: syntax error : missing ';' before identifier 'D'
e:\users\user\documents\visual studio 2008\projects\xlcpp\xlcpp
\xlcpp.cpp 784
Error 22 error C2228: left of '.Borders' must have class/struct/union
e:\users\user\documents\visual studio 2008\projects\xlcpp\xlcpp
\xlcpp.cpp 784
Error 23 error C2228: left of '.Item' must have class/struct/union e:
\users\user\documents\visual studio 2008\projects\xlcpp\xlcpp
\xlcpp.cpp 784
Error 24 error C2228: left of '.Weight' must have class/struct/union e:
\users\user\documents\visual studio 2008\projects\xlcpp\xlcpp
\xlcpp.cpp 784

Those are the only errors the program I've coded sends so far.

The Autowrap IS the OLE Autowrap made by M$ http://support.microsoft.com/kb/216686
 
L

Lucas Coppio

On 1/19/2011 10:54 AM, Lucas Coppio wrote:


I did some of my homework and finally translated the VB script to C++,
but it still don't work, it compiles and start the , but when the
codes reaches the first AutoWrap of my "newly decoded border function"
it crashes the programa.

The code

{

VARIANT xlSolid = {1};
int xlCenter = {-4108};
VARIANT xlBottom = {-4107};
VARIANT xlTop = {-4160};
VARIANT xlRight = {-4152};
VARIANT xlLeft = {-4131};
VARIANT xlCellTypeLastCell = {11};
VARIANT xlThin = {2};
VARIANT xlNone = {-4142};
VARIANT xlContinuous = {1};
VARIANT xlAutomatic = {-4105};
VARIANT xlExpression = {2};

VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters
VARIANT rVal = {0}; // Temporary result holder
int level=0; // Current index into root[]

// Initialize the OLE Library...
// OleInitialize(NULL);

// Line 1: Range B10:I50 . Select
AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"B10:I50",
0);

// Line 2: Selection . Borders xlDiagonalDown . LineStyle =
xlNone
VariantCopy(&rVal, &xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);

// Line 3: Selection . Borders xlDiagonalUp . LineStyle = xlNone
VariantCopy(&rVal, &xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);

// Line 4: With Selection . Borders xlEdgeLeft
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level], &rVal);
VariantClear(&rVal);

// Line 5: . LineStyle = xlContinuous
VariantCopy(&rVal, &xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 6: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 7: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 8: . Weight = xlThin
VariantCopy(&rVal, &xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 9: End With
VariantClear(&root[level--]);

// Line 10: With Selection . Borders xlEdgeTop
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level], &rVal);
VariantClear(&rVal);

// Line 11: . LineStyle = xlContinuous
VariantCopy(&rVal, &xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 12: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 13: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 14: . Weight = xlThin
VariantCopy(&rVal, &xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 15: End With
VariantClear(&root[level--]);

// Line 16: With Selection . Borders xlEdgeBottom
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level], &rVal);
VariantClear(&rVal);

// Line 17: . LineStyle = xlContinuous
VariantCopy(&rVal, &xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 18: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 19: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 20: . Weight = xlThin
VariantCopy(&rVal, &xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 21: End With
VariantClear(&root[level--]);

// Line 22: With Selection . Borders xlEdgeRight
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level], &rVal);
VariantClear(&rVal);

// Line 23: . LineStyle = xlContinuous
VariantCopy(&rVal, &xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 24: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 25: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 26: . Weight = xlThin
VariantCopy(&rVal, &xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 27: End With
VariantClear(&root[level--]);

// Line 28: With Selection . Borders xlInsideVertical
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level], &rVal);
VariantClear(&rVal);

// Line 29: . LineStyle = xlContinuous
VariantCopy(&rVal, &xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 30: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 31: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 32: . Weight = xlThin
VariantCopy(&rVal, &xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 33: End With
VariantClear(&root[level--]);

// Line 34: With Selection . Borders xlInsideHorizontal
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level], &rVal);
VariantClear(&rVal);

// Line 35: . LineStyle = xlContinuous
VariantCopy(&rVal, &xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 36: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 37: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 38: . Weight = xlThin
VariantCopy(&rVal, &xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 39: End With
VariantClear(&root[level--]);

// Line 40: End Sub


// Close the OLE Library...
//OleUninitialize();


// */


}
 
L

Lynn McGuire

On 1/19/2011 10:54 AM, Lucas Coppio wrote:


I did some of my homework and finally translated the VB script to C++,
but it still don't work, it compiles and start the , but when the
codes reaches the first AutoWrap of my "newly decoded border function"
it crashes the programa.

The code

{

VARIANT xlSolid = {1};
int xlCenter = {-4108};
VARIANT xlBottom = {-4107};
VARIANT xlTop = {-4160};
VARIANT xlRight = {-4152};
VARIANT xlLeft = {-4131};
VARIANT xlCellTypeLastCell = {11};
VARIANT xlThin = {2};
VARIANT xlNone = {-4142};
VARIANT xlContinuous = {1};
VARIANT xlAutomatic = {-4105};
VARIANT xlExpression = {2};

VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters
VARIANT rVal = {0}; // Temporary result holder
int level=0; // Current index into root[]

// Initialize the OLE Library...
// OleInitialize(NULL);

// Line 1: Range B10:I50 . Select
AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"B10:I50",
0);

// Line 2: Selection . Borders xlDiagonalDown . LineStyle =
xlNone
VariantCopy(&rVal,&xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);

// Line 3: Selection . Borders xlDiagonalUp . LineStyle = xlNone
VariantCopy(&rVal,&xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);

// Line 4: With Selection . Borders xlEdgeLeft
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);

// Line 5: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 6: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 7: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 8: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 9: End With
VariantClear(&root[level--]);

// Line 10: With Selection . Borders xlEdgeTop
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);

// Line 11: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 12: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 13: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 14: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 15: End With
VariantClear(&root[level--]);

// Line 16: With Selection . Borders xlEdgeBottom
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);

// Line 17: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 18: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 19: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 20: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 21: End With
VariantClear(&root[level--]);

// Line 22: With Selection . Borders xlEdgeRight
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);

// Line 23: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 24: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 25: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 26: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 27: End With
VariantClear(&root[level--]);

// Line 28: With Selection . Borders xlInsideVertical
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);

// Line 29: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 30: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 31: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 32: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 33: End With
VariantClear(&root[level--]);

// Line 34: With Selection . Borders xlInsideHorizontal
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);

// Line 35: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);

// Line 36: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);

// Line 37: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);

// Line 38: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);

// Line 39: End With
VariantClear(&root[level--]);

// Line 40: End Sub


// Close the OLE Library...
//OleUninitialize();


// */


}

I don't think that you are using my code since I dont have an AutoWrap
method.

Also, this code is totally out of my league:
VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters

I think that you are having IDispatch problems with your pointers but
I am not sure. I use IDispatch pointers like this:

void PutStringInServer (int row, int column, std::string string)
{
// get rid of the trailing blanks
string.erase (string.find_last_not_of (' ') + 1);

int len = string.size ();
if (len == 0)
return;

std::string cellAddress = GetCellEquivalent (row, column);
VARIANT result1;
VariantInit ( & result1);
VARIANT range;
VariantInit ( & range);
range.vt = VT_BSTR;
_bstr_t address = _bstr_t (cellAddress.c_str ());
range.bstrVal = address;
std::string errorMsg = "Select a range in the active spreadsheet, " + cellAddress +
" (PutStringInServer)";
OLEMethod (DISPATCH_PROPERTYGET, & result1, pExcelSheet, L"Range", errorMsg, 1, range);
if (result1.vt == VT_DISPATCH)
{
VARIANT result2;
VariantInit ( & result2);
VARIANT value;
VariantInit ( & value);
value.vt = VT_BSTR;
_bstr_t valueBSTR = _bstr_t (string.c_str ());
value.bstrVal = valueBSTR;
std::string errorMsg = "Put the string into the selected cell, " + cellAddress + ", \"" + string + "\"
(PutStringInServer)";
OLEMethod (DISPATCH_PROPERTYPUT, & result2, result1.pdispVal, L"Value", errorMsg, 1, value);
int res = result2.vt;
result1.pdispVal -> Release ();
#ifdef CLEAR_VARIANTS
VariantClear ( & value);
#endif
}
#ifdef CLEAR_VARIANTS
VariantClear ( & range);
#endif

}


Lynn
 
L

Lucas Coppio

I did some of my homework and finally translated the VB script to C++,
but it still don't work, it compiles and start the , but when the
codes reaches the first AutoWrap of my "newly decoded border function"
it crashes the programa.
   VARIANT xlSolid = {1};
   int xlCenter = {-4108};
   VARIANT xlBottom = {-4107};
   VARIANT xlTop = {-4160};
   VARIANT xlRight = {-4152};
   VARIANT xlLeft = {-4131};
   VARIANT xlCellTypeLastCell = {11};
   VARIANT xlThin = {2};
   VARIANT xlNone = {-4142};
   VARIANT xlContinuous = {1};
   VARIANT xlAutomatic = {-4105};
   VARIANT xlExpression = {2};
     VARIANT root[64] = {0}; // Generic IDispatchs
     VARIANT parm[64] = {0}; // Generic Parameters
     VARIANT rVal = {0}; // Temporary result holder
     int level=0; // Current index into root[]
     // Initialize the OLE Library...
    // OleInitialize(NULL);
     // Line 1: Range B10:I50 . Select
     AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"B10:I50",
0);
     // Line 2: Selection . Borders xlDiagonalDown . LineStyle =
xlNone
     VariantCopy(&rVal,&xlNone);
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&root[level--]);
     VariantClear(&rVal);
     // Line 3: Selection . Borders xlDiagonalUp . LineStyle = xlNone
     VariantCopy(&rVal,&xlNone);
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&root[level--]);
     VariantClear(&rVal);
     // Line 4: With Selection . Borders xlEdgeLeft
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     VariantCopy(&root[++level],&rVal);
     VariantClear(&rVal);
     // Line 5: . LineStyle = xlContinuous
     VariantCopy(&rVal,&xlContinuous);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
     VariantClear(&rVal);
     // Line 6: . ColorIndex = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
     VariantClear(&rVal);
     // Line 7: . TintAndShade = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
     VariantClear(&rVal);
     // Line 8: . Weight = xlThin
     VariantCopy(&rVal,&xlThin);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
     VariantClear(&rVal);
     // Line 9: End With
     VariantClear(&root[level--]);
     // Line 10: With Selection . Borders xlEdgeTop
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     VariantCopy(&root[++level],&rVal);
     VariantClear(&rVal);
     // Line 11: . LineStyle = xlContinuous
     VariantCopy(&rVal,&xlContinuous);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
     VariantClear(&rVal);
     // Line 12: . ColorIndex = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
     VariantClear(&rVal);
     // Line 13: . TintAndShade = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
     VariantClear(&rVal);
     // Line 14: . Weight = xlThin
     VariantCopy(&rVal,&xlThin);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
     VariantClear(&rVal);
     // Line 15: End With
     VariantClear(&root[level--]);
     // Line 16: With Selection . Borders xlEdgeBottom
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     VariantCopy(&root[++level],&rVal);
     VariantClear(&rVal);
     // Line 17: . LineStyle = xlContinuous
     VariantCopy(&rVal,&xlContinuous);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
     VariantClear(&rVal);
     // Line 18: . ColorIndex = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
     VariantClear(&rVal);
     // Line 19: . TintAndShade = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
     VariantClear(&rVal);
     // Line 20: . Weight = xlThin
     VariantCopy(&rVal,&xlThin);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
     VariantClear(&rVal);
     // Line 21: End With
     VariantClear(&root[level--]);
     // Line 22: With Selection . Borders xlEdgeRight
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     VariantCopy(&root[++level],&rVal);
     VariantClear(&rVal);
     // Line 23: . LineStyle = xlContinuous
     VariantCopy(&rVal,&xlContinuous);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
     VariantClear(&rVal);
     // Line 24: . ColorIndex = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
     VariantClear(&rVal);
     // Line 25: . TintAndShade = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
     VariantClear(&rVal);
     // Line 26: . Weight = xlThin
     VariantCopy(&rVal,&xlThin);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
     VariantClear(&rVal);
     // Line 27: End With
     VariantClear(&root[level--]);
     // Line 28: With Selection . Borders xlInsideVertical
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     VariantCopy(&root[++level],&rVal);
     VariantClear(&rVal);
     // Line 29: . LineStyle = xlContinuous
     VariantCopy(&rVal,&xlContinuous);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
     VariantClear(&rVal);
     // Line 30: . ColorIndex = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
     VariantClear(&rVal);
     // Line 31: . TintAndShade = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
     VariantClear(&rVal);
     // Line 32: . Weight = xlThin
     VariantCopy(&rVal,&xlThin);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
     VariantClear(&rVal);
     // Line 33: End With
     VariantClear(&root[level--]);
     // Line 34: With Selection . Borders xlInsideHorizontal
     AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
     VariantClear(&parm[0]);
     VariantClear(&parm[1]);
     VariantCopy(&root[++level],&rVal);
     VariantClear(&rVal);
     // Line 35: . LineStyle = xlContinuous
     VariantCopy(&rVal,&xlContinuous);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
     VariantClear(&rVal);
     // Line 36: . ColorIndex = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
     VariantClear(&rVal);
     // Line 37: . TintAndShade = 0
     rVal.vt = VT_I4;
     rVal.lVal = 0;
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
     VariantClear(&rVal);
     // Line 38: . Weight = xlThin
     VariantCopy(&rVal,&xlThin);
     AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
     VariantClear(&rVal);
     // Line 39: End With
     VariantClear(&root[level--]);
     // Line 40: End Sub
     // Close the OLE Library...
     //OleUninitialize();
   //      */

I don't think that you are using my code since I dont have an AutoWrap
method.

Also, this code is totally out of my league:
 >      VARIANT root[64] = {0}; // Generic IDispatchs
 >      VARIANT parm[64] = {0}; // Generic Parameters

I think that you are having IDispatch problems with your pointers but
I am not sure.  I use IDispatch pointers like this:

void PutStringInServer (int row, int column, std::string string)
{
                 //  get rid of the trailing blanks
         string.erase (string.find_last_not_of (' ') + 1);

         int len = string.size ();
         if (len == 0)
...

read more »

No, I'm not using your code.

After a few more hours searching in the internet I've found a guy in a
forum with the same problem I had, and someone solved the problem (and
I did some work to make it fit my purposes)


IDispatch *pXlSheet;
{ //active sheet
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlApp, L"ActiveSheet",
0);
pXlSheet = result.pdispVal;
}

IDispatch *pXlRange2;
for(int aPages = 0; aPages < pages; aPages++){ //selecting range
{
VARIANT parm;
parm.vt = VT_BSTR;
if( aPages == 0)
parm.bstrVal = ::SysAllocString(L"B10:I50");
if( aPages == 1)
parm.bstrVal = ::SysAllocString(L"B60:I100");
if( aPages == 2)
parm.bstrVal = ::SysAllocString(L"B110:I150");
if( aPages == 3)
parm.bstrVal = ::SysAllocString(L"B160:I200");


VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1,
parm);
VariantClear(&parm);
pXlRange2 = result.pdispVal;
}


IDispatch *pXlBorders; //placing borders
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlRange2, L"Borders", 0);

pXlBorders = result.pdispVal;

}

//specify which border to operate on
IDispatch *pXlBorder;

for( int borders = 0, tmpBorder = 7; borders < 6; borders ++,
tmpBorder++){
{
VARIANT item;
item.vt = VT_I4;

//item.lVal=7; //7=left,8=top,9=right,10=bottom

item.lVal=tmpBorder;
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlBorders, L"Item",
1,item);

pXlBorder = result.pdispVal;
}

{
VARIANT value;
value.vt = VT_I4;
value.lVal = 2; //xlThick = 4, xlThin=2
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYPUT, &result, pXlBorder, L"Weight",
1,value);
}

{
VARIANT value;
value.vt = VT_I4;
value.lVal = 1; //xlContinuous
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYPUT, &result, pXlBorder, L"LineStyle",
1,value);
}
{
VARIANT value;
value.vt = VT_I4;
value.lVal = 1; //Black
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYPUT, &result, pXlBorder, L"ColorIndex",
1,value);
}
}
}
 
L

Lynn McGuire

On 1/19/2011 10:54 AM, Lucas Coppio wrote:
I did some of my homework and finally translated the VB script to C++,
but it still don't work, it compiles and start the , but when the
codes reaches the first AutoWrap of my "newly decoded border function"
it crashes the programa.
The code

VARIANT xlSolid = {1};
int xlCenter = {-4108};
VARIANT xlBottom = {-4107};
VARIANT xlTop = {-4160};
VARIANT xlRight = {-4152};
VARIANT xlLeft = {-4131};
VARIANT xlCellTypeLastCell = {11};
VARIANT xlThin = {2};
VARIANT xlNone = {-4142};
VARIANT xlContinuous = {1};
VARIANT xlAutomatic = {-4105};
VARIANT xlExpression = {2};
VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters
VARIANT rVal = {0}; // Temporary result holder
int level=0; // Current index into root[]
// Initialize the OLE Library...
// OleInitialize(NULL);
// Line 1: Range B10:I50 . Select
AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"B10:I50",
0);
// Line 2: Selection . Borders xlDiagonalDown . LineStyle =
xlNone
VariantCopy(&rVal,&xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);
// Line 3: Selection . Borders xlDiagonalUp . LineStyle = xlNone
VariantCopy(&rVal,&xlNone);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&root[level+1],
root[level++].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Borders", 2, rVal, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&rVal);
// Line 4: With Selection . Borders xlEdgeLeft
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 5: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 6: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 7: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 8: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 9: End With
VariantClear(&root[level--]);
// Line 10: With Selection . Borders xlEdgeTop
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 11: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 12: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 13: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 14: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 15: End With
VariantClear(&root[level--]);
// Line 16: With Selection . Borders xlEdgeBottom
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 17: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 18: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 19: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 20: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 21: End With
VariantClear(&root[level--]);
// Line 22: With Selection . Borders xlEdgeRight
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 23: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 24: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 25: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 26: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 27: End With
VariantClear(&root[level--]);
// Line 28: With Selection . Borders xlInsideVertical
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 29: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 30: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 31: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 32: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 33: End With
VariantClear(&root[level--]);
// Line 34: With Selection . Borders xlInsideHorizontal
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD,&rVal,
root[level].pdispVal, L".", 2, parm[1], parm[0]);
VariantClear(&parm[0]);
VariantClear(&parm[1]);
VariantCopy(&root[++level],&rVal);
VariantClear(&rVal);
// Line 35: . LineStyle = xlContinuous
VariantCopy(&rVal,&xlContinuous);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"LineStyle", 1, rVal);
VariantClear(&rVal);
// Line 36: . ColorIndex = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"ColorIndex", 1, rVal);
VariantClear(&rVal);
// Line 37: . TintAndShade = 0
rVal.vt = VT_I4;
rVal.lVal = 0;
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"TintAndShade", 1, rVal);
VariantClear(&rVal);
// Line 38: . Weight = xlThin
VariantCopy(&rVal,&xlThin);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal,
L"Weight", 1, rVal);
VariantClear(&rVal);
// Line 39: End With
VariantClear(&root[level--]);
// Line 40: End Sub
// Close the OLE Library...
//OleUninitialize();

I don't think that you are using my code since I dont have an AutoWrap
method.

Also, this code is totally out of my league:
VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters

I think that you are having IDispatch problems with your pointers but
I am not sure. I use IDispatch pointers like this:

void PutStringInServer (int row, int column, std::string string)
{
// get rid of the trailing blanks
string.erase (string.find_last_not_of (' ') + 1);

int len = string.size ();
if (len == 0)
...

read more »

No, I'm not using your code.

After a few more hours searching in the internet I've found a guy in a
forum with the same problem I had, and someone solved the problem (and
I did some work to make it fit my purposes)


IDispatch *pXlSheet;
{ //active sheet
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result, pXlApp, L"ActiveSheet",
0);
pXlSheet = result.pdispVal;
}

IDispatch *pXlRange2;
for(int aPages = 0; aPages< pages; aPages++){ //selecting range
{
VARIANT parm;
parm.vt = VT_BSTR;
if( aPages == 0)
parm.bstrVal = ::SysAllocString(L"B10:I50");
if( aPages == 1)
parm.bstrVal = ::SysAllocString(L"B60:I100");
if( aPages == 2)
parm.bstrVal = ::SysAllocString(L"B110:I150");
if( aPages == 3)
parm.bstrVal = ::SysAllocString(L"B160:I200");


VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result, pXlSheet, L"Range", 1,
parm);
VariantClear(&parm);
pXlRange2 = result.pdispVal;
}


IDispatch *pXlBorders; //placing borders
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result, pXlRange2, L"Borders", 0);

pXlBorders = result.pdispVal;

}

//specify which border to operate on
IDispatch *pXlBorder;

for( int borders = 0, tmpBorder = 7; borders< 6; borders ++,
tmpBorder++){
{
VARIANT item;
item.vt = VT_I4;

//item.lVal=7; //7=left,8=top,9=right,10=bottom

item.lVal=tmpBorder;
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET,&result, pXlBorders, L"Item",
1,item);

pXlBorder = result.pdispVal;
}

{
VARIANT value;
value.vt = VT_I4;
value.lVal = 2; //xlThick = 4, xlThin=2
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYPUT,&result, pXlBorder, L"Weight",
1,value);
}

{
VARIANT value;
value.vt = VT_I4;
value.lVal = 1; //xlContinuous
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYPUT,&result, pXlBorder, L"LineStyle",
1,value);
}
{
VARIANT value;
value.vt = VT_I4;
value.lVal = 1; //Black
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYPUT,&result, pXlBorder, L"ColorIndex",
1,value);
}
}
}

Glad you found something that worked for you.

Lynn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top