The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Insert header in file from ExportASCII
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Dominik Paulkowski

Germany
Posts

Posted - 05/03/2007 :  11:42:12 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5G SR6
Operating System: Windows XP Prof

Hi, there!

I want to insert header text at the beginning of a file, that was created through wks.ExportASCII.

My script is:

Worksheet wks();
string strFileNameAndPath;

wks.ExportASCII(strFileNameAndPath, WKS_EXPORT_ALL | WKS_EXPORT_LABELS | WKS_EXPORT_MISSING_AS_BLANK, '\t'); // tabulator as separator

string strHeader = "blabla\r";

stdioFile ff(strFileNameAndPath, file::modeReadWrite);
ff.SeekToBegin();
ff.WriteString(strHeader);
ff.Close(); // Close the file

This script overwrites the data in the first row or bit length of strHeader.

How can I insert the header text without overwrite data?

Ciao,
Dominik


-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Mike Buess

USA
3037 Posts

Posted - 05/03/2007 :  12:34:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dominik,

I think you can only overwrite with ff.WriteString so you need to export to a temporary file, create header to data file and copy temporary file to data file...

Worksheet wks = Project.ActiveLayer(); // active wks
string strFileTemp = GetAppPath() + "temp.txt"; // temporary file
wks.ExportASCII(strFileTemp,
WKS_EXPORT_ALL |
WKS_EXPORT_LABELS |
WKS_EXPORT_MISSING_AS_BLANK, '\t'); // tabulator as separator
string strFileNameAndPath = GetAppPath() + "File.dat"; // data file
stdioFile f1(strFileNameAndPath, file::modeReadWrite | file::modeCreate);
stdioFile f2(strFileTemp, file::modeRead);
string strHeader = "blabla\n"; // '\n' is new line
string strLine;
f1.SeekToBegin();
f1.WriteString(strHeader); // write header to file.dat
// copy each line from temp.txt to file.dat
while ( f2.ReadString(strLine) ) f1.WriteString(strLine);
f1.Close(); // close data file
f2.Close(); // close temp file
DeleteFile(strFileTemp); // delete temp file

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/03/2007 12:37:54 PM
Go to Top of Page

Dominik Paulkowski

Germany
Posts

Posted - 05/04/2007 :  03:49:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Mike! Nice idea. It works fine.

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000