Found examples on microsoft firm site

http://code.msdn.microsoft.com/office/CppAutomateExcel-44214081
solution 2

An example is given of how to enable Excel, create a worksheet, write a couple of names and save everything to the xlsx file.

All this in the following form:

VARIANT saNames; saNames.vt = VT_ARRAY | VT_VARIANT; { SAFEARRAYBOUND sab[2]; sab[0].lLbound = 1; sab[0].cElements = 5; sab[1].lLbound = 1; sab[1].cElements = 2; saNames.parray = SafeArrayCreate(VT_VARIANT, 2, sab); SafeArrayPutName(saNames.parray, 1, L"John", L"Smith"); SafeArrayPutName(saNames.parray, 2, L"Tom", L"Brown"); SafeArrayPutName(saNames.parray, 3, L"Sue", L"Thomas"); SafeArrayPutName(saNames.parray, 4, L"Jane", L"Jones"); SafeArrayPutName(saNames.parray, 5, L"Adam", L"Johnson"); } // Fill A2:B6 with the array of values (First and Last Names). // Get Range object for the Range A2:B6 IDispatch *pXlRange = NULL; { VARIANT param; param.vt = VT_BSTR; param.bstrVal = SysAllocString(L"A2:B6"); VARIANT result; VariantInit(&result); AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1, param); pXlRange = result.pdispVal; VariantClear(&param); } { IDispatch *pXlCells, *pXlEntireColumn; VARIANT result; VariantInit(&result); AutoWrap(DISPATCH_PROPERTYGET,&result, pXlSheet,L"Cells", 0); pXlCells=result.pdispVal; VariantInit(&result); AutoWrap(DISPATCH_PROPERTYGET,&result, pXlCells,L"EntireColumn", 0); pXlEntireColumn=result.pdispVal; AutoWrap(DISPATCH_METHOD, NULL,pXlEntireColumn,L"ColumnWidth", 1, 50); } 

The functions in the example are not enough for me. You also need at least a change in the width of the nth column, setting the text color and centering the text in the cell.

When browsing the internet, no detailed documentation was found on these features. Where to find it or ask? What arguments should be passed to the AutoWrap () method to set the width of the column

  • for you to use COM and C ++? - DreamChild
  • I am writing what is needed in order of importance: 1) it is imperative that it be a console one. 2) to run regardless of the version of Windows and Microsoft Office. 3) to run without additional installable libraries. - Pavel

1 answer 1

1) it is necessary that it be a console. 2) to run regardless of the version of Windows and Microsoft Office. 3) to run without additional installable libraries.

then it makes sense for you to forget about COM, since in this case it will be impossible to perform clauses 2 and 3. As far as I know, working with MS Office via COM requires an installed MS Office and cannot be performed with Office from version 2007 or higher. Look in the direction of OpenXML SDK - it is much more convenient than development using COM, does not require an installed Office, and allows you to create and edit documents of the latest office versions.

  • Do you have a sample project? Or at least a piece with a record in Excel? - Pavel
  • I do not have, last time I did this 2 years ago in a previous job. But quite a lot of documentation comes with the SDK with examples - DreamChild
  • It turns out that the application should write on b-sharpe? You can of course on it, but it turns out that the NET Framework will be required? - Paul
  • > but it turns out that the NET Framework will be required? Tell me, where is it now? On computers with OS version <WinXP? I do not think that this is a very significant percentage. In any case, you have to sacrifice something - DreamChild
  • Yes, you were absolutely right) - Paul