open different sheets of excel and write to it using c++
<p>I have an input file "inputfile.txt" from where I am reading input.</p>

<p>inputfile.txt is :-</p>

<pre><code>|I|line|number|1

|P|line|number|2

|I|line|number|3

|P|line|number|4

|I|line|number|5

|P|line|number|6
</code></pre>

<p>Now I am processing this file according to the condition that if second char is I then it will write into "Iout.xls" and if it is 'P' then write to "Pout.xls"</p>

<p>Iout.xls :-</p>

<pre><code>|I|line|number|1

|I|line|number|3

|I|line|number|5
</code></pre>

<p>Pout.xls:-</p>

<pre><code>|P|line|number|2

|P|line|number|4

|P|line|number|6
</code></pre>

<p>both are excel files seperated by pipe.</p>

<p>here is my code what I am doing:-</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;fstream&gt;
#include&lt;string&gt;
#include&lt;vector&gt;
using namespace std;
int main() {
 ifstream in;
 ofstream Iout,Pout;
 string str;
 string::iterator it;
 in.open("inputfile.txt");
 Iout.open("Iout.xls",fstream::app);
 Pout.open("Pout.xls",fstream::app);
 if(in.is_open()){
  while(in.good()) {
   getline(in,str);
   it=str.begin()+1;
   if(*(it)=='I')
     Iout&lt;&lt;str&lt;&lt;endl;
   if(*(it)=='P')
     Pout&lt;&lt;str&lt;&lt;endl;
  }
 }
 else cout&lt;&lt;"can't open file";
 Iout.close();
 Pout.close();
 in.close();
 return 0;
}
</code></pre>

<p>I have two queries:-</p>

<p>1.I am inserting values as a text into excel (for e.g., "|P|line|number|2" is inserted as a text into Pout.xls) and there I am doing text to column manually, Is there any way to automate this using c++.</p>

<p>i.e., |P|line|number|2 will be inserted as:-
  space in first column,P in second column,line in 3rd column,number in 4th column and 2 in 5th column.</p>

<p>my second query:-
I am writing two different files Iout.xls and Pout.xls and then after converting from text to column in both the files,I copy both files into a single file FinalOut.xls with two different sheets Iout and Pout containing the data of Iout.xls and Pout.xls.
How can I open different sheets of an excel file with c++ and write corresponind data directly to the sheets.</p>

<p>i.e., sheet1 will be Iout 
and sheet2 will bePout.</p>

<p>I am using devc++ for my code.</p>

<p>Thank You</p>
