Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29269 Discussions

Creating New worksheet from Intel FORTRAN

hhadavi
Beginner
451 Views
Hi everybody,

I was wondering if anyone know how to add a new excel worksheet to the existing EXCEL workbook using the intel visual fortran.

Thanks
0 Kudos
1 Reply
Paul_Curtis
Valued Contributor I
451 Views
Here is some sample code:

[bash]! Create an Excel object; excelapp = Excel_Create () !CALL COMCREATEOBJECT ("Excel.Application", excelapp, status) IF (excelapp == 0) RETURN CALL $Application_SetVisible (excelapp, TRUE2) CALL $Application_SetScreenUpdating (excelapp, FALSE2) ! Get the WORKBOOKS object workbooks = $Application_GetWorkbooks (excelapp, $STATUS = status) IF (status /= 0) RETURN ! Open a new spreadsheet from the template file workbook = Workbooks_Open (workbooks, tbuf, $STATUS = status) IF (status /= 0) RETURN ! Get the worksheet worksheet = $Workbook_GetActiveSheet (workbook, status) IF (status /= 0) RETURN ! Newer Excel versions require different activition strings, ! according to Intel's AutoDice example ! Excel.Application Excel 2000 and before ! Excel.Application.11 Excel 2003 ! Excel.Application.12 Excel 2007 ! Excel.Application.13 Excel 2010 INTEGER(INT_PTR_KIND()) FUNCTION Excel_Create INTEGER(INT_PTR_KIND()) :: exapp INTEGER :: j CHARACTER(LEN=20) :: appstring = "Excel.Application." CALL COMCREATEOBJECT (appstring(1:17), exapp, status) IF (exapp == 0) THEN ! load fails DO j = 13, 11, -1 WRITE (appstring(19:20), '(I2)') j CALL COMCREATEOBJECT (appstring, excelapp, status) IF (exapp /= 0) EXIT END DO END IF Excel_Create = exapp END FUNCTION Excel_Create[/bash]
0 Kudos
Reply