Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: fstream delete temp file



Permlink Replies: 2 - Last Post: Jun 7, 2015 3:24 PM Last Post By: Andrew McIsaac
Andrew McIsaac

Posts: 93
Registered: 3/12/13
fstream delete temp file
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 5, 2015 3:37 PM
Good afternoon,

This instance : Using XE3 C++ Arch, Windows 7

Created a process that populates a large amount of Data into a StringGrid.
To put this data into Excel, going by looping rows / columns takes way to long.
Therefore, created a way through looping that the StringGrid saves to a text file, ( Using #include <fstream> ) and Excel opens through program control.
Excel can open this file faster than populating each cell from the StringGrid... ( minutes vs. hours)

Problem is the temporary file that was created is being held by Excel, so executable program can not delete this temporary file.
With multiple users, this has potential to fill up drives without knowing ...

Is there a way to set the file to delete once user releases excel file / or saves as something else, or is there a faster way to move large amount of data to Excel ?

Thanks in advance.
Andrew
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: fstream delete temp file
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 5, 2015 4:18 PM   in response to: Andrew McIsaac in response to: Andrew McIsaac
Andrew wrote:

Created a process that populates a large amount of Data into a
StringGrid.

TStringGrid is not designed to handle large amounts of data. I would strongly
suggest you consider another component. Either a 3rd party Excel-like component,
or TVirtualTreeView in a list/grid mode, or just a standard TListView in
virtual mode, or even TDrawGrid with owner-drawn cells.

To put this data into Excel, going by looping rows / columns takes
way to long.

Which is why you should not do it that way. Put your actual data into a
list in memory instead, or even a local/embedded database, and loop through
that instead of TStringGrid itself. Then switch to a virtual-mode component
that can display the data from your data souce without having to put the
data inside of the component itself.

Excel can open this file faster than populating each cell from the
StringGrid... ( minutes vs. hours)

I would hope so. Microsoft is pretty big about using virtualized UIs for
large data displays. And for good reason - the performance gains are enormous
for large amounts of data.

Problem is the temporary file that was created is being held by Excel,
so executable program can not delete this temporary file.

Is there a way to set the file to delete once user releases excel file

There is nothing you can do about Excel holding on to the file.

However, you CAN delete a file while it is still open and the OS will delay
physically deleting the file from disk until all handles to the file have
been closed.

If Excel prevents that action, another thing you might try is open the file
yourself first using CreateFile() with the FILE_FLAG_DELETE_ON_CLOSE flag
enabled (and adequate sharing rights so Excel can also open the file), then
let Excel open the file before you close your handle to it. When Excel closes
its handle to the file, it will auto-delete. But this requires Excel to
open the file with FILE_SHARE_DELETE access, which I doubt it does, so this
will probably not work.

Or, you may just have to resort to using MoveFileEx(MOVEFILE_DELAY_UNTIL_REBOOT)
to delete the temp file on the next OS reboot.

or is there a faster way to move large amount of data to Excel ?

What about using OLE Automation to control Excel directly, and push your
data directly into its cells instead of using a file at all?

--
Remy Lebeau (TeamB)
Andrew McIsaac

Posts: 93
Registered: 3/12/13
Re: fstream delete temp file
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2015 3:24 PM   in response to: Andrew McIsaac in response to: Andrew McIsaac
Thank you so much

I had tried the included components ( ExcelWorkSheet1, Workbook1 ... ), but I will also try the OLE directly.

Thank you,
Andrew
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02