473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Exporting from C to Excel.

3
I've got a program in C that creates a 2 dimensional array pN with dimensions of [nt] and [nx]. I need to export the array to excel, so I can do useful math on it.

I can get the fwrite command to save a 1d array for me, but not a 2d array. Tried looking up programming guides online, and all the ones I could find are limited to 1d arrays as well.


The best I could come up with was to try and break my array up into a bunch of 1 dimensional arrays, and export each of them individually. However, since my 2d array is something like 300 X 1000 (exact size depends on user input), this isn't a very practical solution, even when put inside a for loop.

I've got all of 4 days programming experience, and don't speak "programmer" at all, so if you could limit your explanation to common english (as hard as I'm sure that is) I would greatly appriciate some help.




*Note, for what I want to do to the data later, I do need to export specifically to Excel. If there's a shortcut for doing that versus exporting to a more general format (like a .txt file or a generic spreadsheet), I'd rather take the shortcut.

Thanks in advance.
Mar 6 '07 #1
4 10159
sicarie
4,677 Expert Mod 4TB
I've got a program in C that creates a 2 dimensional array pN with dimensions of [nt] and [nx]. I need to export the array to excel, so I can do useful math on it.

I can get the fwrite command to save a 1d array for me, but not a 2d array. Tried looking up programming guides online, and all the ones I could find are limited to 1d arrays as well.


The best I could come up with was to try and break my array up into a bunch of 1 dimensional arrays, and export each of them individually. However, since my 2d array is something like 300 X 1000 (exact size depends on user input), this isn't a very practical solution, even when put inside a for loop.

I've got all of 4 days programming experience, and don't speak "programmer" at all, so if you could limit your explanation to common english (as hard as I'm sure that is) I would greatly appriciate some help.




*Note, for what I want to do to the data later, I do need to export specifically to Excel. If there's a shortcut for doing that versus exporting to a more general format (like a .txt file or a generic spreadsheet), I'd rather take the shortcut.

Thanks in advance.
The best idea I can think of is to print them to a file, comma-delimited, to import into Excel.

When you say you can do it for a 1d array, but not a 2d, what are you trying, and what did that return? Can you just not print the 2d array (the values for the first show up, but not the second)?
Mar 6 '07 #2
HKKID
3
The best idea I can think of is to print them to a file, comma-delimited, to import into Excel.

When you say you can do it for a 1d array, but not a 2d, what are you trying, and what did that return? Can you just not print the 2d array (the values for the first show up, but not the second)?
actually I can get it to Print the 2d array using the code below, I just can't figure out how to SAVE it.

Expand|Select|Wrap|Line Numbers
  1. for (i=0; i <= nx; i++)
  2.         {
  3.         for (m=1; m<=nt; m++)
  4.             {
  5.             printf("%f", pn[i][m]);
  6.             printf("    ");
  7.             }
  8.         printf("\n");
  9.         } 
As for what I'm trying... I figured I would need something like this:

Expand|Select|Wrap|Line Numbers
  1. // code to create my array//
  2.  
  3. FILE *fp;
  4.  
  5. fp=fopen("spreadsheetname.xls", wb);  /* I have no idea why the "wb" is there, but it shows up in all the examples I could find, so I'm assuming it matters */
  6.  
  7. fwrite(pn, [[something to indicate the location of the data I want to save]], [[something to indicate location on the .xls file to put the data]], fp);
  8.  
  9. fclose(fp);
But, I've got no clue what the syntax for the part in the middle should be.

For sake of reference, the relevant part of the programming guide I've been using is Here.
Mar 6 '07 #3
Banfa
9,065 Expert Mod 8TB
fwrite writes binary data which is not what you want, it is not outputting the data in a format readable by Excel. For the format to be readable by Excel it will also need to be readable by you in Notepad.

However all is not lost, there is a function fprintf, this is very similar to printf except that it outputs to a file rather than the screen.

You will need to alter you printf loop to an fprintf loop and also make it output a comma instead of the spaces between each value.


I will say this though, c is capable of doing any calculations that Excel is and if you plan envolves Exporting to Excel doing some calculations and then re-Imorting the data back to the program then I would say you are making a serious design error.
Mar 6 '07 #4
HKKID
3
I will say this though, c is capable of doing any calculations that Excel is and if you plan envolves Exporting to Excel doing some calculations and then re-Imorting the data back to the program then I would say you are making a serious design error.
Thanks for the help!

And to answer your question, I may be new at C, but I'm not an idiot. I wasn't planning on importing my data back into the program. I have a pre-built mathematica program that does peak fitting, uncertainty analysis, and a few other useful things for me. All i need to make that program do the things I'm interested in, is my data saved as a .xls file :-p.
Mar 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
2
by: G | last post by:
When I export data from access to excel by with "export" or "Analyze with" I seem to loose parts of some fields (long text strings). Is there a way to export it all to excel? Thanks G
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
5
by: Neil | last post by:
Hi I'm currently exporting my datagrid to excel, taking advantage of the fact that excel can render html, the problem is that when i click the button to export it opens in browser, I want the button...
2
by: Mustufa Baig | last post by:
Hi everybody, I have an ASP.NET website where clients can view their monthly billings by selecting different options. One of the option is the way they want to see the report i.e. whether they...
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
4
by: Tom | last post by:
I have a gridview on all of my web pages in my web app and they all export to excel. I have one page where the gridview is binding to a datatable that i created and only the first column is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.