PDA

View Full Version : Output Table



ToddAtWSU
20th March 2013, 18:55
I have been requested to write an application that will search through hundreds of directories of data, parse specific files, and output this data into a table. This part will be fairly simple, but the part I am having issues with is then the customers are requesting the ability to copy this table data and paste it into Microsoft Word. The only method I can come up with is to save the output in a CSV format to then load into Excel. Once Excel is displaying this information, the user could then copy the table from Excel into Word.

I would prefer to avoid the Excel middle-man method if at all possible. Is there anything inside Qt that will allow me to display a table that can be copied into Word? Or at worst, a way to output a file that Word can import directly without using Excel? I originally thought maybe some sort of RTF viewer, but playing around in MS Wordpad makes me think maybe RTF can't handle tables.

Thanks for any help you have for this.
Todd

d_stranz
21st March 2013, 01:02
How about a hybrid solution? Use Qt to copy the data to the clipboard in CSV format, then write a Word macro that will copy that CSV and create a table on the fly? No doubt Google might even be able to help you find such a macro that someone has already written.

If you are displaying the data in a QTableWidget / View, you can iterate over the rows and retrieve the QTableWidgetItems column-by-column, and then use the QTableWidgetItem::text() method to retrieve the cell content. Build up a big QString by continuously appending the text, delimited by commas and newlines, then copy the whole thing to the clipboard. I use this method for copying tables into Excel and have never run into a problem with the string being too large or the clipboard being unable to hold it.

This link (http://help.lockergnome.com/office/Filling-Table-csv-file--ftopict615794.html) might help with the macro on the Word side.

ChrisW67
21st March 2013, 02:38
What happens if you load the QClipboard with the QMimeData containing markup for an HTML table ? What does Word do when you paste this?

ToddAtWSU
21st March 2013, 12:13
I think your idea is similar to what I came up with overnight. I am thinking I could display the table in a QTextDocument which is HTML and then I should be able to paste the HTML into Word and then they can tweak and format the table however they prefer in their Word Document. I have never used the QClipboard before. What makes it special versus just letting the OS handle Copying?

d_stranz
21st March 2013, 16:17
There is nothing special about QClipboard - you call clear() to empty it, setText() to put text data on it. If you want to put a mime type, like HTML, then you create a QMimeData instance, call setHtml() on it with a QString containing the html, then call the clipboard's setMimeData() method. You use QApplication::clipboard() to get a pointer to the global instance.

Using QMimeData will set the mime type to text/html. If Word can import a table in html, then you should be home free. You could test this without a lot of coding by writing a dummy program that puts some HTML into a QString, copies it into a QMimeData object, then posts that to the QClipboard. If the Edit->Paste operation in Word sees it and does the right thing, then you can implement it for real.

I wouldn't trust simply going to a web page and copying the html in a browser, unless you can verify that the mime type on the clipboard really is text/html and not just plain old ASCII.

Just curious - your description sounds like this might be a bioinformatics project. Is it?

A.Rock
9th April 2013, 16:47
Hi, I am new to Qt. I have to do an application similar to yours. could you explain me how to search through hundreds of directories of data, parse specific files, and output this data into a table.?.
which application did you use?.
sorry for the stupid question, but I am a completely beginner.

ChrisW67
9th April 2013, 21:55
could you explain me how to search through hundreds of directories of data, parse specific files, and output this data into a table.
Here are the big steps:

Open the top directory
Step through every file and sub-directory in the directory
If a file matches "specific files"

Open the file
Read data from the file
If data is of interest output the data to a table/file/whatever

When you see a subdirectory call this routine again treating it as the top directory
When you finish processing the directory return



which application did you use?.
This is a programmer's forum... ToddAtWSU is writing the program to do that using Qt