Click here to Skip to main content
15,885,921 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi, Im learning on how to Extract a simple 2 dimensional arrays int values into the Excel file. i find many examples of doing that in c# however i was unable to convert it into a C++ format.

Below is the simple 2 dimensional array code i have wrote to test. if possible please guide me along the 2 dimensional array if i have made any mistake.

Thank you.

C#
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

                unsigned int ptr = 0;

                 int** array_ptr;
                     array_ptr = new int * [1000];// Declare 1000 rows of arrays
                 for(int i = 0; i < 1000; i++)
                 {
                     array_ptr[i] = new int[1536]; // 1536 column
                 }

                 for(int y = 0; y <1000; y++)
                 {
                     for(int x = 0; x <1536; x++)
                     {
                         ptr++;
                         array_ptr[y][x] = (unsigned)(int) ptr;
                             //MessageBox::Show("ok");
                         textBox1->Text = Convert::ToString(array_ptr[800][264]);

                     }
                 }

             }
Posted
Updated 2-Jul-12 22:06pm
v2

1 solution

Hi, answered a similar question a while ago. It involved automating Excel from C++, _without_ MFC. Perhaps it will be of use to you? Though I would suppose that using winforms, you can import Excel objects. (Don't know - never done winforms)

See the c++ solution here[^]
 
Share this answer
 
Comments
NypStu 4-Jul-12 1:41am    
Hi enhzflep, thanks for your help , i just realised that i have declared 1536 columns X 1000 row of int. i think it would be impossible to export all the value into the excel file. however is it possible to export it into a notepad or any other software which will be able to keep and store such a large amount of int?
Thanks
enhzflep 4-Jul-12 5:32am    
No problem NypStu. Just tried the code with an array of that size, it worked fine. I'll admit it took a couple of seconds for the call to put the array contents into the cells, but I suppose it was over 1.5 million elements.

You could certainly save the same information to a text file with ease. After opening the file, you'd just have a pair of for loops to print all the elements of the array.

There's code that interacts with excel that looks like t may be a good article for you, over here: Use VS2008 C/CLI to Automate Excel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900