예제 #1
0
        public unsafe static uint GetCurrentSheetId12()
        {
            XlOper12 SRef = new XlOper12();

            SRef.xlType = XlType12.XlTypeSReference;
            //SRef.srefValue.Count = 1;
            //SRef.srefValue.Reference.RowFirst = 1;
            //SRef.srefValue.Reference.RowLast = 1;
            //SRef.srefValue.Reference.ColumnFirst = 1;
            //SRef.srefValue.Reference.ColumnLast = 1;

            XlOper12  resultOper  = new XlOper12();
            XlOper12 *pResultOper = &resultOper;

            XlOper12 * pSRef  = &SRef;
            XlOper12 **ppSRef = &(pSRef);
            int        xlReturn;

            xlReturn = Excel12v(xlSheetNm, 1, ppSRef, pResultOper);
            if (xlReturn == 0)
            {
                XlOper12 ResultRef = new XlOper12();
                xlReturn = Excel12v(xlSheetId, 1, (XlOper12 **)&(pResultOper), &ResultRef);
                if (xlReturn == 0 && ResultRef.xlType == XlType12.XlTypeReference)
                {
                    return(ResultRef.refValue.SheetId);
                }
            }
            return(0);
        }
예제 #2
0
        private unsafe static int TryExcelImpl12(int xlFunction, out object result, params object[] parameters)
        {
            int xlReturn;

            // Set up the memory to hold the result from the call
            XlOper12 resultOper = new XlOper12();

            resultOper.xlType = XlType12.XlTypeEmpty;
            XlOper12 *pResultOper = &resultOper;  // No need to pin for local struct

            // Special kind of ObjectArrayMarshaler for the parameters (rank 1)
            using (XlMarshalXlOperArrayContext paramMarshaler
                       = new XlMarshalXlOperArrayContext(1, true))
            {
                XlOper12 **ppOperParameters = (XlOper12 **)paramMarshaler.ObjectArrayReturn(parameters);
                xlReturn = Excel12v(xlFunction, parameters.Length, ppOperParameters, pResultOper);
            }

            // pResultOper now holds the result of the evaluated function
            // Get ObjectMarshaler for the return value
            result = XlMarshalContext.ObjectParam((IntPtr)pResultOper);

            // And free any memory allocated by Excel
            Excel12v(xlFree, 1, &pResultOper, (XlOper12 *)IntPtr.Zero);

            return(xlReturn);
        }
예제 #3
0
        private unsafe static int TryExcelImpl12(int xlFunction, out object result, params object[] parameters)
        {
            int xlReturn;

            // Set up the memory to hold the result from the call
            XlOper12 resultOper = new XlOper12();

            resultOper.xlType = XlType12.XlTypeEmpty;
            int       i           = sizeof(XlOper12);
            XlOper12 *pResultOper = &resultOper;  // No need to pin for local struct

            // Special kind of ObjectArrayMarshaler for the parameters (rank 1)
            using (XlObjectArray12Marshaler paramMarshaler = new XlObjectArray12Marshaler(1, true))
            {
                XlOper12 **ppOperParameters = (XlOper12 **)paramMarshaler.MarshalManagedToNative(parameters);
                xlReturn = Excel12v(xlFunction, parameters.Length, ppOperParameters, pResultOper);
            }

            // pResultOper now holds the result of the evaluated function
            // Get ObjectMarshaler for the return value
            ICustomMarshaler m = XlObject12Marshaler.GetInstance("");

            result = m.MarshalNativeToManaged((IntPtr)pResultOper);
            // And free any memory allocated by Excel
            Excel12v(xlFree, 1, &pResultOper, (XlOper12 *)IntPtr.Zero);

            return(xlReturn);
        }
예제 #4
0
        public unsafe static IntPtr GetCurrentSheetId12()
        {
            // In a macro type function, xlSheetNm seems to return the Active sheet instead of the Current sheet.
            // So we first try to get the Current sheet from the caller.
            IntPtr retval = GetCallerSheetId12();

            if (retval != IntPtr.Zero)
            {
                return(retval);
            }

            // Else we try the old way.
            XlOper12 SRef = new XlOper12();

            SRef.xlType = XlType12.XlTypeSReference;
            //SRef.srefValue.Count = 1;
            //SRef.srefValue.Reference.RowFirst = 1;
            //SRef.srefValue.Reference.RowLast = 1;
            //SRef.srefValue.Reference.ColumnFirst = 1;
            //SRef.srefValue.Reference.ColumnLast = 1;

            XlOper12  resultOper  = new XlOper12();
            XlOper12 *pResultOper = &resultOper;

            XlOper12 * pSRef  = &SRef;
            XlOper12 **ppSRef = &(pSRef);
            int        xlReturn;

            xlReturn = Excel12v(xlSheetNm, 1, ppSRef, pResultOper);
            if (xlReturn == 0)
            {
                XlOper12  resultRef  = new XlOper12();
                XlOper12 *pResultRef = &resultRef;
                xlReturn = Excel12v(xlSheetId, 1, (XlOper12 **)&(pResultOper), pResultRef);

                // Done with pResultOper - Free
                Excel12v(xlFree, 1, &pResultOper, (XlOper12 *)IntPtr.Zero);

                if (xlReturn == 0)
                {
                    if (resultRef.xlType == XlType12.XlTypeReference)
                    {
                        retval = resultRef.refValue.SheetId;
                    }
                    // Done with ResultRef - Free it too
                    Excel12v(xlFree, 1, &pResultRef, (XlOper12 *)IntPtr.Zero);
                }
                // CONSIDER: As a small optimisation, we could combine the two calls the xlFree. But then we'd have to manage an array here.
            }
            return(retval);
        }
예제 #5
0
 public static unsafe IntPtr GetCallerSheetId12()
 {
     IntPtr retval = IntPtr.Zero;
     XlOper12 resultOper = new XlOper12();
     XlOper12* pResultOper = &resultOper;
     int xlReturn;
     xlReturn = Excel12v(xlfCaller, 0, (XlOper12**)IntPtr.Zero, pResultOper);
     if (xlReturn == 0)
     {
         if (resultOper.xlType == XlType12.XlTypeReference)
         {
             retval = resultOper.refValue.SheetId;
             Excel12v(xlFree, 1, &pResultOper, (XlOper12*)IntPtr.Zero);
         }
     }
     return retval;
 }
예제 #6
0
 public unsafe static IntPtr GetCallerSheetId12()
 {
     IntPtr retval = IntPtr.Zero;
     XlOper12 resultOper = new XlOper12();
     XlOper12* pResultOper = &resultOper;
     int xlReturn;
     xlReturn = Excel12v(xlfCaller, 0, (XlOper12**)IntPtr.Zero, pResultOper);
     if (xlReturn == 0)
     {
         if (resultOper.xlType == XlType12.XlTypeReference)
         {
             retval = resultOper.refValue.SheetId;
             Excel12v(xlFree, 1, &pResultOper, (XlOper12*)IntPtr.Zero);
         }
     }
     return retval;
 }
예제 #7
0
        private static unsafe int TryExcelImpl12(int xlFunction, out object result, params object[] parameters)
        {
            int xlReturn;

            // Set up the memory to hold the result from the call
            XlOper12 resultOper = new XlOper12();
            resultOper.xlType = XlType12.XlTypeEmpty;
            XlOper12* pResultOper = &resultOper;  // No need to pin for local struct

            // Special kind of ObjectArrayMarshaler for the parameters (rank 1)
            using (XlObjectArray12Marshaler.XlObjectArray12MarshalerImpl paramMarshaler
                        = new XlObjectArray12Marshaler.XlObjectArray12MarshalerImpl(1, true))
            {
                XlOper12** ppOperParameters = (XlOper12**)paramMarshaler.MarshalManagedToNative(parameters);
                xlReturn = Excel12v(xlFunction, parameters.Length, ppOperParameters, pResultOper);
            }

            // pResultOper now holds the result of the evaluated function
            // Get ObjectMarshaler for the return value
            ICustomMarshaler m = XlObject12Marshaler.GetInstance("");
            result = m.MarshalNativeToManaged((IntPtr)pResultOper);
            // And free any memory allocated by Excel
            Excel12v(xlFree, 1, &pResultOper, (XlOper12*)IntPtr.Zero);

            return xlReturn;
        }
예제 #8
0
        public static unsafe IntPtr GetCurrentSheetId12()
        {
            // In a macro type function, xlSheetNm seems to return the Active sheet instead of the Current sheet.
            // So we first try to get the Current sheet from the caller.
            IntPtr retval = GetCallerSheetId12();
            if (retval != IntPtr.Zero)
                return retval;

            // Else we try the old way.
            XlOper12 SRef = new XlOper12();
            SRef.xlType = XlType12.XlTypeSReference;
            //SRef.srefValue.Count = 1;
            //SRef.srefValue.Reference.RowFirst = 1;
            //SRef.srefValue.Reference.RowLast = 1;
            //SRef.srefValue.Reference.ColumnFirst = 1;
            //SRef.srefValue.Reference.ColumnLast = 1;

            XlOper12 resultOper = new XlOper12();
            XlOper12* pResultOper = &resultOper;

            XlOper12* pSRef = &SRef;
            XlOper12** ppSRef = &(pSRef);
            int xlReturn;
            xlReturn = Excel12v(xlSheetNm, 1, ppSRef, pResultOper);
            if (xlReturn == 0)
            {
                XlOper12 resultRef = new XlOper12();
                XlOper12* pResultRef = &resultRef;
                xlReturn = Excel12v(xlSheetId, 1, (XlOper12**)&(pResultOper), pResultRef);

                // Done with pResultOper - Free
                Excel12v(xlFree, 1, &pResultOper, (XlOper12*)IntPtr.Zero);

                if (xlReturn == 0)
                {
                    if (resultRef.xlType == XlType12.XlTypeReference)
                    {
                        retval = resultRef.refValue.SheetId;
                    }
                    // Done with ResultRef - Free it too
                    Excel12v(xlFree, 1, &pResultRef, (XlOper12*)IntPtr.Zero);
                }
                // CONSIDER: As a small optimisation, we could combine the two calls the xlFree. But then we'd have to manage an array here.
            }
            return retval;
        }
예제 #9
0
        internal static unsafe void SetExcelReference12(XlOper12* pOper, XlOper12.XlMultiRef12* pMultiRef, object /*ExcelReference*/ r)
        {
            IntPtr sheetId = ExcelReferenceGetSheetId(r);
            int[][] rects = ExcelReferenceGetRectangles(r);
            int rectCount = rects.GetLength(0);

            pOper->xlType = XlType12.XlTypeReference;
            pOper->refValue.SheetId = sheetId;

            pOper->refValue.pMultiRef = pMultiRef;
            pOper->refValue.pMultiRef->Count = (ushort)rectCount;

            XlOper12.XlRectangle12* pRectangles = (XlOper12.XlRectangle12*)(&pOper->refValue.pMultiRef->Rectangles);

            for (int i = 0; i < rectCount; i++)
            {
                pRectangles[i].RowFirst = rects[i][0];
                pRectangles[i].RowLast = rects[i][1];
                pRectangles[i].ColumnFirst = rects[i][2];
                pRectangles[i].ColumnLast = rects[i][3];
            }
        }
예제 #10
0
        public unsafe static IntPtr GetCurrentSheetId12()
        {
            IntPtr retval = IntPtr.Zero;
            XlOper12 SRef = new XlOper12();
            SRef.xlType = XlType12.XlTypeSReference;
            //SRef.srefValue.Count = 1;
            //SRef.srefValue.Reference.RowFirst = 1;
            //SRef.srefValue.Reference.RowLast = 1;
            //SRef.srefValue.Reference.ColumnFirst = 1;
            //SRef.srefValue.Reference.ColumnLast = 1;

            XlOper12 resultOper = new XlOper12();
            XlOper12* pResultOper = &resultOper;

            XlOper12* pSRef = &SRef;
            XlOper12** ppSRef = &(pSRef);
            int xlReturn;
            xlReturn = Excel12v(xlSheetNm, 1, ppSRef, pResultOper);
            if (xlReturn == 0)
            {
                XlOper12 resultRef = new XlOper12();
                XlOper12* pResultRef = &resultRef;
                xlReturn = Excel12v(xlSheetId, 1, (XlOper12**)&(pResultOper), pResultRef);

                // Done with pResultOper - Free
                Excel12v(xlFree, 1, &pResultOper, (XlOper12*)IntPtr.Zero);

                if (xlReturn == 0)
                {
                    if (resultRef.xlType == XlType12.XlTypeReference)
                    {
                        retval = resultRef.refValue.SheetId;
                    }
                    // Done with ResultRef - Free it too
                    Excel12v(xlFree, 1, &pResultRef, (XlOper12*)IntPtr.Zero);
                }
                // CONSIDER: As a small optimisation, we could combine the two calls the xlFree. But then we'd have to manage an array here.
            }
            return retval;
        }