LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write data into an existing .xlsx file.

Hi,

 

I want to use the report generation toolkit to save to an existing Excel file. But all it is doing is creating a new Excel and I have to save it. How do I save to an existing file. I am using the report generation toolkit because I need to save in .xlsx format and also be able to choose the worksheet in which I save. I have attached the code. Thank You. 

0 Kudos
Message 1 of 12
(1,232 Views)

Hi govindsankar,

 

the way you create the path to your template XLSX seems wrong to me:

Are you sure the correct template file is used by the RGT functions?

(Btw. there is a BuildPath function to create a filepath!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(1,210 Views)

The build path is not important. I can directly connect a path to it and still get the same result that is open a new .xlsx file instead of adding to existing one. I have uploaded a updated one with a direct path instead of built path. With this program I get the same output as before. 

0 Kudos
Message 3 of 12
(1,203 Views)

Hi govindsankar,

 


@govindsankar wrote:

The build path is not important. I can directly connect a path to it and still get the same result that is open a new .xlsx file instead of adding to existing one. I have uploaded a updated one with a direct path instead of built path. With this program I get the same output as before. 


You forgot to actually save your report - you just edit the template!

Use the DisposeReport function…

 

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 12
(1,194 Views)

DisposeReport function is creating a copy of the original file and not saving it to the existing file. 

0 Kudos
Message 5 of 12
(1,161 Views)

Hi govindsankar,

 


@govindsankar wrote:

DisposeReport function is creating a copy of the original file and not saving it to the existing file. 


Nope, for me it saved the template file…

(What have you tried now?)

 

This worked for me:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 12
(1,151 Views)

Hi govindsankar,

 

- Use "Create Report" to open your existing excel file;

- Do your modifications;

- Use "Save Report to File" with the same path to save changes;

- Use "Close Report" to close the ressources.

 

Also, it seems you are using deprecated VIs (red-crossed icons).

 

Regards,

Raphaël.

0 Kudos
Message 7 of 12
(1,144 Views)

There is no create report in the report generation toolkit for me. 

0 Kudos
Message 8 of 12
(1,127 Views)

Got it. Finally got it working. 

0 Kudos
Message 9 of 12
(1,108 Views)

There are some subtle omissions in the posted code examples (although Raphaël got it right).  If you want to insert information into an existing Workbook/Worksheet, you need to do the following:

  1. Open Excel (using "New Report" or "Create Report", depending on which version of LabVIEW you are running), specifying the path to the existing Workbook.  [If you specify a blank Workbook, it is as though you didn't use the Template entry].
  2. By default (I think, and I haven't checked this), you should be "positioned" on WorkSheet 1.  If your Template has multiple WorkSheets, you may want to set the current WorkSheet.
  3. Use Excel Easy Table to insert a 1D or 2D array of String or Numeric data at the "Start" location (a cluster that uses "LabVIEW Array Addressing", so the upper left Cell is (0, 0)) to insert your data.  Note that this function passes out two "next" locations, the next Cell Address to insert more data below your last Insert and the next Cell Address to insert more data to the right of your last Insert.  This can be extremely handy, and avoids your having to "compute next Excel coordinates".
  4. When you are ready to save the Template, you need to write it to Excel using Save Report to File.  Note that you must specify a file name for this -- if you specify the same file that you used as your Template, you will overwrite the Template file.  [This may be exactly what you want to do, but if you are really using it as a "Template", i.e. a partly-filled-in Excel Workbook where you "Insert the Data" in specific named Cells, you might want to "save" using a different name.  It's up to you.]
  5. Now you want to close Excel and make sure that your (new) Excel file is saved.  I recommend (based on experience that spans about a decade of RGT use) that you put a brief delay (maybe 100 msec) here to let Excel finish writing the file, and then do a Dispose Report, which closes Excel.  At this point, you definitely want a brief delay, especially if you are going to do another Report.

That should work.  Try it, and if it doesn't, make a folder with your VI + the Template file (.xlsx) that you want to use + a Data file that you want to insert into the Template (and where you want it to go).  Giving us Real Code and Real Data to chew on will let one (or more!) of us return a "Fixed Example" to you.

 

Bob Schor

0 Kudos
Message 10 of 12
(1,101 Views)