I created a project that will collect a lot of data, save it, and ultimately want to print out the sheets of data as a hard-copy. Although I've been using the simple output to a text file -- the user still has to find the text file, open it, switch the layout to landscape mode, then print it.
I was considering dumping this text file into excel (without creating a CSV file that the user will have to open with excel). I've used a program that would detect excel being open already, and dump all data into the cells automatically. Then it would just be simply clicking print from that point.
Or should I try to format this output another way? Anyone have any luck in getting a nice hard copy with minimal effort on the USER end? ( I don't want to create a file that the user has to open through excel ) Perhaps at the end of the program interface with a -USB- printer and print automatically from the program?
Well, if it's not going to be TOO MUCH data, you could hold it in memory until the very end, then copy the formatted text to the clipboard. Additionally, you could play a sound to let the user know that the data is ready to be pasted.
Excel and similar spreadsheet programs will automatically put in different columns strings separated by '\t'. For example, for the string "one\ttwo\tthree", each word would be going in a different column.
EDIT: Oh, you could also write the file anyway, and then tell Excel to open it through the command line. Just don't use system(), for god's sake. Use CreateProcess().
system() is blocking, which means that instead of exiting as soon as possible, his program will be bound to Excel's fate unless his user knows about ctrl+c or ctrl+break.
And then dump the data cell by cell instead? To allow for formatting options -- size of text, etc? Would I need to use more system commands? -- Trying to find some resources on how to use system();
I personally would try and go with HelioS idea first. System should probably only be used for last resort or be used temporarily until a better solution is found.
I'm trying to find the best solution for the end-user that is the simpliest on their part. Not having to copy and paste anything or format the page. I've looked through the few C++ books and resources I could find any nothing is there on loading outside programs or formatting an output other than a simple text file. What is the best solution?
I explained it rather thoroughly in my first post, including how to format plain text so that Excel-like programs load different data into different columns, and what Windows API function to call to start Excel and pass it command line arguments. Which part don't you understand?
The best solution is to use Excel as an OLE component in your application. That is essentially the same as embedding an Excel spreadsheet into your application, and you can control it.
The next best is helios's approach -- create the tab-delimited text file and use CreateProcess() to start Excel with the text file name as the command-line argument.
The last, but simplest, approach is to use system().