Unsolved Export QTableView to Excel file
-
hello friends, i have a query about a QTableView.
My question is how can I export the data that I have in my QTableView to an excel file, that is, how can I create a file from the Table, is it possible to do that in Qt, I would appreciate any suggestions, greetings -
Iterate over the model and write the data out into a csv file.
-
Hi,
first result from Google asked "qt xls" https://wiki.qt.io/Handling_Microsoft_Excel_file_formatYou can, of course, implement something yourself, xls format is dumb, it is actually zipped folder tree: https://docs.fileformat.com/spreadsheet/xlsx/
EDIT: of course, @Christian-Ehrlicher is also right, you can use intermediate file like csv for the import purpose.
-
@lincoln
I had to do this in my first Qt code. Write an export to Excel/PDF of anyQTableView
. I didn't find, or choose to use, anything ready-made. It's a lot easier to do it via a.csv
file as @Christian-Ehrlicher says. Do it from the model.I also allowed to produce Excel file for control over layout etc., but I was in Python so able to use an export-to-XLSX library which may not be available to you if you are C++. (BTW, via CSV file you can have data values for cells and that's it; you cannot make it look like the
QTableView
with widths or colours or lines or anything. If that is important for your usage you can't go via CSV, just so you know.) -
ok thanks, I'll try to do what you suggest, the important thing is to migrate that data to an excel because they ask for it at work.
-
@lincoln Did you get the way to do it ?
Can you share your code if you have done it