Click here to Skip to main content
12,997,158 members (67,464 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.

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++)
                         array_ptr[y][x] = (unsigned)(int) ptr;
                         textBox1->Text = Convert::ToString(array_ptr[800][264]);
Posted 2-Jul-12 20:55pm
Updated 2-Jul-12 22:06pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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[^]
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?
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100