LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Merge excel files

Solved!
Go to solution

Hello everyone,

 

im stuck with a (maybe) simple problem, and i can't find the solution 😕 

 

I have a folder with several excel files which are generated during the code,the excel files are saved in a folder.  I would like to merge all excel files that belong to the same frame e.g.: cell_frame1_1, cell_frame1_2, cell_frame1_3 in the folder into one excel file.


Does anyone have an idea how I could implement this in LabVIEW?

 

please can someone help me? i would be really grateful!!

 

Thanks in advance.

 

0 Kudos
Message 1 of 11
(1,904 Views)

Hi Ayman,

 

use RGT functions to handle/create Excel files...

 

Are we talking about XLS* files - or are they CSV files?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(1,866 Views)
Solution
Accepted by topic author AymanB95

Ayman,

 

     It is difficult to answer your question because you provided ambiguous (and incomplete) information.  It would have helped us to better understand your situation if you did the following:

  1. Attached your LabVIEW code (the actual file(s) with extension ".vi") that you are trying to "make work".
  2. Attach a sample "Excel file" and clarify how the other "Excel files" are the same, or are different.

     As Gerd mentioned, new LabVIEW programmers often say "Excel" when they mean ordinary text files read by LabVIEW's "Read Delimited Spreadsheet".  If these are saved with the extension ".csv", which means "Comma-Separated Values", and signifies a Text file with rows (of numeric or string) data separated by New Lines and columns separated by commas, Windows will create a "phony" Excel-like Icon for these files, causing many new LabVIEW users to mis-call these "Excel" files.

 

     If this is the type of file you have, combining them into one is easy.  Here's how to do it:

  • Come up with code that gets you all of the files that you want to read (and combine into a "summary" file).  If there is a "pattern" to the file names ("cell_frame1_"<n>), you can use the File Dialog Express VI to return a list of files (in a specified Folder) that "match" a certain pattern.  Now you have an Array of "Files to be read".
  • Decide on the name of the "Merge" File.
  • In a For loop (being fed the Array of Input files),
    • Open the Input file.
    • With a While loop,
      • Read a line from the Input File, and write it to the Output File.
      • Stop when you reach the end of the Input file.
  • When the For loop ends, close the Merge file.  Done.

Note that if your "input" files have a Header (or two), you may need to copy the Header from the first file, and decide to not copy the Header from the remaining files.

 

OK, so what if you really have Excel files (cell_frame1_1.xlsx)?  The Algorithm is basically the same as for Delimited Spreadsheets, except you are not dealing with Text files (which LabVIEW can easily read, one line at a time, which corresponds to reading "rows" and ignoring the fact that there are "column-separating characters" in the line), but with data maintained by Excel.  So you need to know how to get rows of Data from Excel, and to put rows of Data to another Excel file.

 

Eight years ago, I posted a Revised "Generate Excel Report" Example that showed how to write an Excel file with "Rows and Columns of Data" in a specific location in an output Excel "Report".  But how do you read an Excel file (to get the data you'll need to write)?

 

The "trick" is hidden in "Create Report", which allows you to specify a "Template" file that is opened and read when the Report opens.  Excel Get Data (and Excel Get Last Row) can "get the Data" from a Template, after which you can close the Template.  Now you have a choice -- the simplest thing is to save the 2D data from this first file, read the second file and add the data to the end of the Array, until you read (and concatenated) all the Data, then "Create Report" (without a Template) and (using the Excel Easy Table function) write the (concatenated) data to the Report, then Save Report to File (using the "Output" name) and Dispose Report (to close Excel).  Whew!

 

Whichever method is suitable to your situation (which we would know if you attached your code), I urge you to try to program the appropriate algorithm for yourself.  Don't try to do it "all at once" -- start by figuring out how to read a named file (and look at the Data you got from reading the file -- does it match the file contents?  Are there the right number of rows and columns?).  Once you get one file, test out your ability to determine the "list of files" that you want to process (using the File routines mentioned in the first Algorithm).  Did you get all the names, and are they "correct"?  Keep adding (small) pieces until you have an entire working routine.

 

Bob Schor

 

0 Kudos
Message 3 of 11
(1,842 Views)

Online, the recommended way to do merge Excel files (any way you want to) is to use Power Query.

 

There seems to be a Power Query SDK, so you could try to invoke a Power Query from LabVIEW using the SDK and .NET functions. 

0 Kudos
Message 4 of 11
(1,829 Views)

Thank you so much! I followed your suggestions and it worked 🙂

0 Kudos
Message 5 of 11
(1,813 Views)

How do you insert a saved csv file into an existing excel templet file that has cell formatting in place?

0 Kudos
Message 6 of 11
(1,426 Views)

Hello, @BGarber05.  Welcome to the LabVIEW Forums.  As this is your first Post, you might 

0 Kudos
Message 7 of 11
(1,406 Views)

Oops!  Not sure what happened, but I seem to have turned off my computer, not realizing I had started a reply, and found this waiting a few hours later.  Sorry about that.

 

I was going to ask @BGarber05, a new member, to "Start a New Topic", clearly describing the (slightly different) topic of interest, rather than "taking over" another topic whose solution had already been posted.  @BGarber05 could explain the nature of the problem to be solved, and could also tell us "what I tried, what worked, what didn't work, what I don't know how to do, etc." and could also supply us with LabVIEW code (preferably "saved for Previous Version", like LabVIEW 2019 or 2021, so more of the "experienced users", who might not have migrated to the most recent version of LabVIEW (which is not "viewable" (yet) by older versions of the software, could see it and offer suggestions.

 

So, my apologies.  I'm interested in learning what, precisely, the "new" issue is, and will follow the New Message that @BGarber05 posts.

 

Bob Schor

0 Kudos
Message 8 of 11
(1,397 Views)

OK Thank You.  I wasn't sure how to create a new post since I'm new at this so I just figured I'd throw it out there.

0 Kudos
Message 9 of 11
(1,373 Views)

@BGarber05 wrote:

OK Thank You.  I wasn't sure how to create a new post since I'm new at this so I just figured I'd throw it out there.


Go to the main forum page:

wiebeCARYA_0-1686837601423.png

Press START A TOPIC.

 

Obviously 😁 (iff you been on the forum 25 years 🙄).

0 Kudos
Message 10 of 11
(1,359 Views)