/*------------------------------------------------------------------------------* * File Name: ReportCreation.c * * Creation: ER, 07/25/02 * * Purpose: OriginC example for COM connectivity with MSOffice * * Copyright (c) OriginLab Corp. 2001, 2002, 2003, 2004, 2005, 2006, 2007 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ //////////////////////////////////////////////////////////////////////////////////// // #include // //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// // This example illustrates accessing MSOffice programs from Origin C using COM. // OriginPro is required for this program to function. // The function CreateReport() does the following: // 1> Opens an Excel Workbook named ExcelData.XLS from the \OriginC\Samples\COM folder // 2> Reads the data in all (2) worksheets of this sample Excel file // 3> Graphs the data in Origin using a custom template, and performs nonlinear curve fitting // 4> Exports the resulting graph with fit curve, to a BMP file // 5> Creates a new Word document for each worksheets, using custom template // 6> Places the graph image, and other relevant information into the Word document // // To run this function, first compile this file, then go to the Origin Script Window // (Origin menu item: Window | Script Window), and type the following and hit Enter: // CreateReport // void CreateReport() { // Bring up wait cursor waitCursor wCursor; printf("Processing..."); // Get Path of current C file - all other files for this example are in the same subfolder string strFldPath = GetFilePath(__FILE__); // Declare Excel objects Object oExcel, oExcelWkbks, oExcelWkbk, oExcelWksh; // Create an Excel application object and set it as invisible oExcel = CreateObject("excel.application"); oExcel.Visible = false; // Get the workbooks collection of the Excel object oExcelWkbks = oExcel.Workbooks; // Open the workbook with data to be analyzed oExcelWkbk = oExcelWkbks.Open(strFldPath+ "ExcelData.xls"); // Create a Word application object and set as invisible Object oWord, oWordDoc; oWord = CreateObject("word.application"); oWord.Visible = false; // Loop over each worksheet in the Excel workbook foreach (oExcelWksh in oExcelWkbk.Worksheets) { // Read the number of points in the dataset int npts = oExcelWksh.Cells(7,2).Value; // Read start x value double xstart = oExcelWksh.Cells(5,2).Value; // Read step x value double xstep = oExcelWksh.Cells(6,2).Value; // Define Origin vectors to hold data vector vecX, vecY; vecX.SetSize(npts); vecY.SetSize(npts); // Fill x vector using x start and x step values for (int ii = 0; ii