LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete Excel Sheet

Help me please!
I export data to Excel (using ActiveX).
Can I delete some sheet in workbook (for example workbook contain 3 sheets (a,b,c), and I want delete only 'b') using LV tools?
0 Kudos
Message 1 of 11
(6,917 Views)
Hello,
Modifying documents through external programs using ActiveX can be a tricky thing to do. The process of deleting a worksheet is similar to that of adding a worksheet (which you can see in the 'Write to Table to XL.vi' example in the example finder) however you will need to specify the specific worksheet to delete. You can do this with the "item" invoke node. Please see the attached example program. It should give you a good idea of how you can do this. Best of luck!

Regards,
Chris J
Applications Engineer
National Instruments
Message 2 of 11
(6,891 Views)
I developped a similar example, but each time I got an annoying dialog box asking me if I was sure I wanted to delete the sheet since the data would be irremediably lost. Now I can't reproduce this behaviour ! Any suggestion on how to get rid of Excel dialog boxes ?

BTW
1/the index, in the "Sheets" property node, can be alternatively connected to an integer (1 to n) representing the relative position of the sheets.
2/ you missed closing the "Worbooks" reference...
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 3 of 11
(6,875 Views)
Hello Charly,
You are correct ... in both cases. You can wire a numeric constant to specify the sheet you would like to delete. When using this you may want to be careful because Excel appears to index from the left most sheet and not necessarily the sheet number (ie if sheet 4 is left of sheet 1, 2, and 3 and your index is 1, Excel will delete sheet 4) Also, I missed closing the workbooks reference in my example code. Thank you for bringing that to my attention. To answer your question, if you expand the first first property node in the code above to include the display alerts property you can wire in a False constant. This should disable the alerts so that you no longer get the dialogue box asking if you are sure you want to delete. (Note: you may wish to reset this before closing the program because this tells Excel to never ask if you want to save anything ever again). I hope this helps!

Best Regards,
Chris J
Applications Engineer
National Instruments
Message 4 of 11
(6,851 Views)
Great !
Thanks for your answer. May be I'll reconsider using Excel in my applications. :).

I have another question. A few days ago somebody asked if there was a way of copying and pasting between a LV table and Excel. The problem is that when you select a range of cells in a LV table and try to paste it in Excel, you only paste a picture of the table ! In the other direction, nothing happens...
Copy/paste can works between 2 LV tables, if you use the copy data/paste data commands that are in "data operations" sub-menu, but there is no direct way to exchange with other applications.
Any comment/idea/workaround ???

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 5 of 11
(6,837 Views)
Hi!
I try to open this example, but it made in LV 7.1.
I have only 6.0... 😞
Could you make screen shot from that vi?

Thanks!
0 Kudos
Message 6 of 11
(6,834 Views)
Hello Charly,
You are correct. Copy and pasting directly from a LabVIEW table into Excel will only copy a picture of the table. LabVIEW uses a slightly different data type for its table and not tab or comma separated values like Excel. One thing you may want to consider is wiring your table data into the “Array to Spreadsheet String.vi” and then into a string indicator. You can then copy and paste directly from the string indicator into Excel. (Note: You can also go the other way using a string control to populate your table with the “Spreadsheet String to Array.vi”).

PS - Prog, I have attached the screenshot from my previous program below.

Best Regards,
ChrisJ
Applications Engineer
National Instruments
Message 7 of 11
(6,818 Views)

@ChrisJ wrote:
...One thing you may want to consider is wiring your table data into the “Array to Spreadsheet String.vi” and then into a string indicator. You can then copy and paste directly from the string indicator into Excel.

Thanks for the idea, but that's not what I would like to do. May be a workaround could be to manage directly the clipboard content ? That way, it should be possible, after intercepting the Copy command, to read the selected area on the table and to convert to a spreadsheet string before filling the clipboard.
Have you any idea on how to read/write to the clipboard with LabVIEW ?

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
0 Kudos
Message 8 of 11
(6,809 Views)
I've seen several things about working with the clipboard. Try searching for it here.
I think if you only want to manage text, you can do so fairly easily through the windows API. Try searching the MSDN for clipboard.
Also, if I'm not mistaken, G toolbox has something to deal with this, maybe even in the free section. Try looking there too.

___________________
Try to take over the world!
0 Kudos
Message 9 of 11
(6,801 Views)
I have another question 🙂
How I can copy excel sheet from one workbook to another?
For example, book A contain 3 sheets (a,b,c) and I want to copy sheet 'b' to book B (using LV tools).

Thanks!
Message 10 of 11
(6,769 Views)