Hi all !
Thanks for the suggestions by
Trake and
lockdown & at the same time apologizing for failing to update you about the progress so far.
In fact the number of errors reduced from 4 to 2 (50% off). But i still get some 2 errors that I worked around to eliminate, but couldn't.
The complete code and the newly generated errors are as follows:
CODE
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <fstream>
using std::ifstream;
#include <cstdlib> // for exit function
using namespace std;
// method to read a 3X3 array from the only sheet (Sheet1) in an excel file named "Books2.xls"
const int nRows2 =3;
const int nCols2 =3;
void readArray(int myArray[nRows2][nCols2]) {
// to open an excel file "Book2.xls" for reading
ifstream CSpreadsheet;
CSpreadsheet.open("Book2.xls",ios::in); // Can be ios:::in or ios:::out depending on what you want to do
ifstream CSpreadsheet("Book2.xls");
if (CSpreadsheet.is_open()) {
for (int row = 0; row <nRows2; row++) {
for (int col = 0; col <nCols2; col++) {
// To accept/read-in values for the array
CSpreadsheet >> myArray[row][col];
}
}
}
else {
cout << "Can't open your Excel file";
}
CSpreadsheet.close();
}
// Method to display/write contents of the earlier read array in another excel file named "Book3.xls"
void displayMyArray(int myArray[nRows2][nCols2])
{ // to open a file "examples_output.txt" for output
ofstream CSpreadsheet;
CSpreadsheet.open ("Book3.xls", ios::out);
if (CSpreadsheet.is_open()){
for (int row = 0; row < nRows2; row++){
for (int col = 0; col < nCols2; col++){
// to print out elements of an array
CSpreadsheet << myArray[row][col] << '\t';}
CSpreadsheet << endl <<endl;}
}
else {
cout << "Can't open file for writing";
}
CSpreadsheet.close();
}// method displayMyArray ends here
int main () {
int myArray[nRows2][nCols2];
readArray(myArray);
displayMyArray(myArray);
return 0;
}
While the error message is:
1>------ Build started: Project: project2, Configuration: Debug Win32 ------
1>Compiling...
1>project2.cpp
1>.\project2.cpp(177) : error C2370: 'CSpreadsheet' : redefinition; different storage class
1> .\project2.cpp(175) : see declaration of 'CSpreadsheet'
1>.\project2.cpp(182) : error C2088: '>>' : illegal for class
1>Build log was saved at "file://c:\Users\m.babanfati\Documents\Visual Studio 2008\Projects\project2\Debug\BuildLog.htm"
1>project2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any further suggestion is highly appreciated.
QUOTE(lockdown @ 3 Jan, 2008 - 08:59 AM)

QUOTE(Trake @ 3 Jan, 2008 - 05:25 AM)

I think you shouldn't be using:
CODE
ifstream myExcelFile CSpreadsheet("Book2.xls", "Sheet1");
I think it should just be:
CODE
ifstream CSpreadsheet("Book2.xls", "Sheet1");
That is some what correct. The if stream is just creating the stream you will be using to write information to. You then need to open the file you want the information written to and tell what you are doing (commonly open or close).
CODE
ifstream CSpreadsheet;
CSpreadsheet.open("Book2.xls",ios:::in); // Can be ios:::in or ios:::out depending on what you want to do
// Your information
CSpreadsheet.close
From my code above I have removed Sheet 1 since that will be the default sheet that will open when the application access the excel file. Now I am not a expert in the stream commands so I am not sure how it would open two files. But from what I can assume and some what understand having the Sheet1 in their makes the program think to open another file. But I am not sure if that is correct. Either way in this instance you would be fine by remove Sheet 1 because it defaults to that. But if you wanted a different sheet I am not sure.
I could be wrong though because I have only worked with spread sheets once in this fashion and that was awhile back.
Here is a site that explains the ifstream, its commands, and parameters.
http://www.cplusplus.com/reference/iostrea...tream/open.html