Update of /cvsroot/objecthandler/ObjectHandler/gensrc/stubs
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26478/gensrc/stubs
Modified Files:
stub.excel.exports stub.excel.includes stub.excel.register
stub.excel.unregister
Log Message:
new function ohPack()
Index: stub.excel.exports
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.exports,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stub.excel.exports 6 Jun 2006 09:08:30 -0000 1.1
--- stub.excel.exports 14 Jun 2006 13:15:25 -0000 1.2
***************
*** 3,6 ****
--- 3,7 ----
#define ohxl_export_hpp
+ #pragma comment (linker, "/export:_ohPack")
%s
Index: stub.excel.register
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.register,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stub.excel.register 6 Jun 2006 09:08:30 -0000 1.1
--- stub.excel.register 14 Jun 2006 13:15:25 -0000 1.2
***************
*** 3,6 ****
--- 3,18 ----
void ohRegisterFunctions(const XLOPER &xDll) {
+ Excel(xlfRegister, 0, 11, &xDll,
+ TempStrNoSize("\x06""ohPack"), // function code name
+ TempStrNoSize("\x03""RP#"), // parameter codes
+ TempStrNoSize("\x06""ohPack"), // function display name
+ TempStrNoSize("\x10""inputRange"), // comma-delimited list of parameter names
+ TempStrNoSize("\x01""1"), // function type (1 = worksheet function)
+ TempStrNoSize("\x0D""ObjectHandler"), // function category
+ TempStrNoSize("\x00"""), // shortcut text (command macros only)
+ TempStrNoSize("\x00"""), // path to help file
+ TempStrNoSize("\x3D""trim #ERR/empty values from bottom/right edges of input range"), // function description
+ TempStrNoSize("\x1D""range of cells to be packed ")); // description of parameter 1
+
%(xlregister)s
Index: stub.excel.unregister
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.unregister,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stub.excel.unregister 6 Jun 2006 09:08:30 -0000 1.1
--- stub.excel.unregister 14 Jun 2006 13:15:25 -0000 1.2
***************
*** 9,12 ****
--- 9,27 ----
XLOPER xlRegID;
+ Excel(xlfRegister, 0, 11, &xDll,
+ TempStrNoSize("\x06""ohPack"), // function code name
+ TempStrNoSize("\x03""RP#"), // parameter codes
+ TempStrNoSize("\x06""ohPack"), // function display name
+ TempStrNoSize("\x10""inputRange"), // comma-delimited list of parameter names
+ TempStrNoSize("\x01""0"), // function type (0 = worksheet function)
+ TempStrNoSize("\x0D""ObjectHandler"), // function category
+ TempStrNoSize("\x00"""), // shortcut text (command macros only)
+ TempStrNoSize("\x00"""), // path to help file
+ TempStrNoSize("\x3D""trim #ERR/empty values from bottom/right edges of input range"), // function description
+ TempStrNoSize("\x1D""range of cells to be packed ")); // description of parameter 1
+
+ Excel4(xlfRegisterId, &xlRegID, 2, &xDll,
+ TempStrNoSize("\x06""ohPack")); // function code name
+
%(xlunregister)s
Index: stub.excel.includes
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.includes,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** stub.excel.includes 9 Jun 2006 18:58:27 -0000 1.2
--- stub.excel.includes 14 Jun 2006 13:15:25 -0000 1.3
***************
*** 22,23 ****
--- 22,104 ----
}
+ int countValidRows(const XLOPER &xMulti) {
+ for (int numValidRows=xMulti.val.array.rows; numValidRows; numValidRows--) {
+ for (int i=0; i<xMulti.val.array.columns; i++) {
+ int index = (numValidRows - 1) * xMulti.val.array.columns + i;
+ if (!(xMulti.val.array.lparray[index].xltype & (xltypeErr | xltypeNil)))
+ return numValidRows;
+ }
+ }
+ return 1;
+ }
+
+ int countValidCols(const XLOPER &xMulti) {
+ for (int numValidCols=xMulti.val.array.columns; numValidCols; numValidCols--) {
+ for (int i=0; i<xMulti.val.array.rows; i++) {
+ int index = (numValidCols - 1) + i * xMulti.val.array.columns;
+ if (!(xMulti.val.array.lparray[index].xltype & (xltypeErr | xltypeNil)))
+ return numValidCols;
+ }
+ }
+ return 1;
+ }
+
+ XLL_DEC XLOPER *ohPack(OPER *xInputRange) {
+
+ boost::shared_ptr < ObjHandler::FunctionCall > functionCall;
+ XLOPER xMulti;
+ static XLOPER xRet;
+ xRet.val.array.lparray = 0;
+
+ try {
+ functionCall = boost::shared_ptr < ObjHandler::FunctionCall >
+ ( new ObjHandler::FunctionCall("ohPack") );
+
+ Excel(xlCoerce, &xMulti, 2, xInputRange, TempInt(xltypeMulti));
+
+ int numValidRows = countValidRows(xMulti);
+ int numValidCols = countValidCols(xMulti);
+
+ xRet.val.array.rows = numValidRows;
+ xRet.val.array.columns = numValidCols;
+ xRet.val.array.lparray = new XLOPER[numValidRows * numValidCols];
+ if (!xRet.val.array.lparray)
+ throw ObjHandler::Exception("ohPack: error on call to new");
+ xRet.xltype = xltypeMulti | xlbitDLLFree;
+
+ for (int i=0; i<numValidRows; i++) {
+ for (int j=0; j<numValidCols; j++) {
+ int indexSource = i * xMulti.val.array.columns + j;
+ int indexTarget = i * numValidCols + j;
+ ObjHandler::operToOper(&xRet.val.array.lparray[indexTarget],
+ &xMulti.val.array.lparray[indexSource]);
+ }
+ }
+
+ Excel(xlFree, 0, 1, &xMulti);
+ return &xRet;
+ } catch (const std::exception &e) {
+
+ // free any memory that may have been allocated
+
+ Excel(xlFree, 0, 1, &xMulti);
+
+ if (xRet.xltype & xltypeMulti && xRet.val.array.lparray) {
+ for (int i=0; i<xRet.val.array.columns * xRet.val.array.rows; i++) {
+ if (xRet.val.array.lparray[i].xltype & xltypeStr && xRet.val.array.lparray[i].val.str)
+ delete [] xRet.val.array.lparray[i].val.str;
+ }
+ delete [] xRet.val.array.lparray;
+ }
+
+ // log the exception and return a null pointer (#NUM!) to Excel
+
+ std::ostringstream err;
+ err << "ohPack - ";
+ if (functionCall) err << functionCall->getAddressString() << " - ";
+ err << e.what();
+ ObjHandler::logMessage(err.str(), 2);
+ return 0;
+ }
+ }
+
|