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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Insert header in file from ExportASCII

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Dominik Paulkowski Posted - 05/03/2007 : 11:42:12 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
Dominik Paulkowski Posted - 05/04/2007 : 03:49:46 AM
Thanks, Mike! Nice idea. It works fine.

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany
Mike Buess Posted - 05/03/2007 : 12:34:36 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000