08-29-2022 11:04 AM - edited 08-29-2022 11:10 AM
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.
Solved! Go to Solution.
08-29-2022 02:31 PM
08-29-2022 08:35 PM
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:
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:
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
08-30-2022 03:26 AM
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.
08-30-2022 05:57 AM
Thank you so much! I followed your suggestions and it worked 🙂
06-14-2023 10:48 AM
How do you insert a saved csv file into an existing excel templet file that has cell formatting in place?
06-14-2023 04:33 PM
Hello, @BGarber05. Welcome to the LabVIEW Forums. As this is your first Post, you might
06-14-2023 08:24 PM
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
06-15-2023 07:35 AM
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.
06-15-2023 09:01 AM
@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:
Press START A TOPIC.
Obviously 😁 (iff you been on the forum 25 years 🙄).