Using TWAPI for Writing Data to Excel

Girish2121
Girish2121 Altair Community Member
edited October 2020 in Community Q&A

Hi all,

 

I am looking out for any examples to write stress/node id data to excel sheet TWAPI in Tcl/Tk.

 

Thanks in advance,

Regrads,

Girish C Hirekerur

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited April 2016

    Hi,

    If you just want to write raw data, write it as CSV text format (can be opened by excel)

    example

    set fpt [open example.csv w]

    puts $fpt 'NodeID,StressValue'

    puts $fpt [join 1 100]

    puts $fpt [join 2 200]

    puts $fpt [join 3 300]

    close $fpt

     

     

    ==> open example.csv by excel to see

  • Girish2121
    Girish2121 Altair Community Member
    edited April 2016

    Hi Tinh,

     

    I need to write the data from Hyperview in an organised readable manner.I referred to an example as given below :

     

      package require twapi
       
      set excel [::twapi::comobj Excel.Application]
      $excel DisplayAlerts [expr 0]
       
      set workbooks [$excel Workbooks]
      $workbooks Open 'C:/Users/willblatt/BlattBros/Projects/10000 Temp/XLS_Files_Chip/CHIP_ASSAY_TABLE.xlsx'
       
      set workbook [$workbooks Item 1]
      set sheets [$workbook Sheets]
      set sheet [$sheets Item 1]
      set cells [$sheet range a1 c3]
       
      puts [$cells Value]
       
      $cells -destroy
      $sheet -destroy
      $sheets -destroy
      $workbook -destroy
      $workbooks -destroy
      $excel Quit
     

    $excel -destroy

     

    I tried to use the above example.

    i.How should I add New Sheet to the file.

    ii.Can change the name of the file from Sheet1,Sheet2,etc. to something different say :Normal Force,Axial Force.etc

    iii. Any detailed documentation of all the classes available in TWAPI ?

     

    Thanks in advance,

    Girish

  • tinh
    tinh Altair Community Member
    edited April 2016

    Hi,

    there is document of using twapi. you can search it on google

    for excel COM, perhaps you should look at MSDN

    https://msdn.microsoft.com/en-us/library/office/ff193217.aspx

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited April 2016

    Why need XLS when you can make CSV?