LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

different worksheet for every loop

hi, i want to save data in different 47  worksheets in single workbook of xlsx file for every  loop ie. 47.

but the problem is that it saved the data in same worksheet 1 for every loop 

please help me to sort out this problem,thanks.

 

Download All
0 Kudos
Message 1 of 9
(2,965 Views)

Before Writing data use Excel get WorkSheet.Vi to Select the Expected Worksheet as Current worksheet and then try to write the data.

use Loops with Array of Worksheet as input to the Loop Control.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 9
(2,956 Views)

hi,thanks for reply.

can you please explain it briefly what does this mean "use Loops with Array of Worksheet as input to the Loop Control"

Thanks.

0 Kudos
Message 3 of 9
(2,938 Views)

Excel.png

 

Worksheet Index Defines the Array of worksheet  Indices of your choice.

All rows Defines the Value.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 4 of 9
(2,918 Views)

While PalanivelIT's response is (mostly) correct, it may well fail "in the real world".  You need to think about Excel's behavior when creating a new Workbook and Worksheets (which may well differ with different versions of Excel -- I'm using Office 2013, which shares behavior with Office 2007 and 2010).

 

When you open Excel and don't specify a Workbook (using New Report without specifying a Template), Excel gives you a 3-Worksheet Workbook, with Sheet 1, Sheet 2, and Sheet 3.  In the example shown below, I've got an array of "Station Numbers" (nominally 1 through, say, 14, but possibly with a few Stations not in the array, e.g. 1, 2, 5, 7, 8, 10, 14).  I want to create a Workbook with Worksheets named "Station 1", "Station 2", "Station 5", etc.  When I create a New Report, I get the Worksheets Count (3 in Excel 2013, but why assume?), and using the Array of Stations to drive a For loop, I either use Get Worksheet (for the first three loops) or Add Worksheet (for the remaining Stations).  I then build the Sheet Name ("Station %2d") and rename it with Excel Rename Worksheet.  [In this particular VI, I also initialize the Worksheet by creating Column Headers and setting some Formatting choices).  

 

Once I have all of the Worksheets initialized, another VI takes the array of data (one "chunk" for each Worksheet, which are now all appropriately named) and simply fills each Worksheet in the Workbook.  [If you can't tell, I'm a great believer in having multiple subVIs that each do a little defined piece of the Puzzle -- in this instance, I have one VI that determines which Stations are present, this VI that initializes the Workbook (and creates named Worksheets, one per Station), the VI described at the beginning of this paragraph that takes the array of Stations, gets a Station-sized "chunk" of data, and writes it on the Station's Worksheet, and a final VI that closes the Workbook, looking similar to the final two Report Functions shown by PalanivelIT.]

Initialize Workbook.png

Bob Schor

Message 5 of 9
(2,909 Views)

hi bob,thanks for reply.

i tryed the way you explained above but didn't find out the solution ,the problem still exist .

Instead of creating different worksheet the program stores the data in single worksheet .

i have attached the vi and excel file.

Download All
0 Kudos
Message 6 of 9
(2,897 Views)

ransher a écrit :

hi bob,thanks for reply.

i tryed the way you explained above but didn't find out the solution ,the problem still exist .

Instead of creating different worksheet the program stores the data in single worksheet .

i have attached the vi and excel file.


The problem is not with Bob's code, it's how you use it and all the rube coding. What you want can probably be accomplished within a single loop. We don't have a clear idea of what you exactly want to accomplish. You should attach your csv file with typical data and an xlsx file that contain a few pages of the format you expect.

 

You also seem to use Bob code without really understanding what it does. The false case is not wired trough and what do you think the worksheets numeric control is used for? The way you use it all the sheets will have the same name, probably not what you want. Also, the same array will be written to all sheets.

 

Ben64

Message 7 of 9
(2,875 Views)

Just Share us the Raw Input and and your Expected data in the Excel, we will try to replicate the same in dynamic way.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 8 of 9
(2,860 Views)

oh sorry, i forget to tell that i have made the code and it's working fine,thanks for reply.

0 Kudos
Message 9 of 9
(2,836 Views)