473,883 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create an excel file through a C program

I need to create an excel file through a C program and then to populate
it.How can it be done?

Apr 28 '06 #1
27 27459
jeniffer wrote:
I need to create an excel file through a C program and then to populate
it.How can it be done?

Ask microsoft for the file format, then write the code to produce the file.

--
Ian Collins.
Apr 28 '06 #2
jeniffer opined:
I need to create an excel file through a C program and then to
populate it.How can it be done?


By learning about Excel file format (if M$ lets you), which is
off-topic here. Once you do, and you have some C code that gives you
troubles, feel free to come back here for help.

On the most basic level, you'd need `fopen()`, `fwrite()`, and friends
from <stdio.h>.

--
Under every stone lurks a politician.
-- Aristophanes

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

Apr 28 '06 #3
In article <11************ **********@u72g 2000cwu.googleg roups.com>,
jeniffer <ze************ ******@gmail.co m> wrote:
I need to create an excel file through a C program and then to populate
it.How can it be done?


fopen() the file with "wb" (write binary) mode, and
then fwrite() or fprintf() or putc() or fputc() whatever you need to.

You should probably avoid putw() and fputs(), though:
putw() works in terms of the type "int", which is not the same
size on all systems; and fputs() includes a terminating newline,
which is not the same character(s) on all systems.
What you need now is to know what the structure is of an excel file.
That's a topic beyond the scope of standard C, and is
subject to change without notice from Microsoft ("Documentin g
a file structure hurts our ability to innovate!!") Inc.

You can find a long paper on the file format by googling for
excel file structure
for example, http://sc.openoffice.org/excelfileformat.pdf
has OpenOffice's documentation up to Excel 2003. You will likely
find the mass of information there rather daunting, and chances
are extremely high that if you were to attempt to implement the
full range yourself that you (or anyone) would make mistakes.
I would therefor suggest to you that you should either attempt to
find a pre-written Excel library (perhaps OpenOffice offers one),
or else that you take a big portability hit by confining yourself
to Windows and using one of Microsoft's development APIs.
Microsoft's APIs are discussed in microsoft-specific newsgroups.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Apr 28 '06 #4

jeniffer schrieb:
I need to create an excel file through a C program and then to populate
it.How can it be done?


Better you use in this case Visual Basic! Much easier and comfortable.

Apr 28 '06 #5
Zero opined:

jeniffer schrieb:
I need to create an excel file through a C program and then to
populate it.How can it be done?


Better you use in this case Visual Basic! Much easier and
comfortable.


Another possibility: use CSV format (comma separated values).

--
Beware of the Turing Tar-pit in which everything is possible but
nothing of interest is easy.

<http://clc-wiki.net/wiki/Introduction_to _comp.lang.c>

Apr 28 '06 #6
On 2006-04-28, jeniffer <ze************ ******@gmail.co m> wrote:
I need to create an excel file through a C program and then to populate
it.How can it be done?


Probably create a .csv file (which you can do with normal fprintf and
string processing in C), and use Excel to import that.

Otherwise there is possibly a library, or some way to use Excel as a
co-process, you'd have to find out about Office and Microsoft
architecture.
Apr 28 '06 #7
Zero wrote:
jeniffer schrieb:
I need to create an excel file through a C program and then to populate
it.How can it be done?


Better you use in this case Visual Basic! Much easier and comfortable.

You scum. VB isn't a language. "Languages" work in more than one
environment.

My friend made a one-window app with two prompts and nothing else, and
it took up 3 megs of RAM. I made the same thing in C (with curses), and
it used about 50K, which seemed like a lot to me at the time...

--
"Every prime number in a series as a joke
Made all the patterns clear when I took that final toke"
- - Andrew Poelstra <http://www.wpsoftware. net/blog>
Apr 28 '06 #8
jeniffer wrote:

I need to create an excel file through a C program and then to
populate it. How can it be done?


FILE *excelfile;

if (NULL == (excelfile = fopen("filename ", "w")))
exit(EXIT_FAILU RE);
else {
while (suitablecondit ions) fwrite(excelfil e, data);
}
fclose(excelfil e);

You will have to define filename, suitableconditi ons, and data for
yourself.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
Apr 28 '06 #9
In article <44************ ***@yahoo.com>,
CBFalconer <cb********@mai neline.net> wrote:
jeniffer wrote:
I need to create an excel file through a C program and then to
populate it. How can it be done?

FILE *excelfile; if (NULL == (excelfile = fopen("filename ", "w")))
exit(EXIT_FAILU RE);


excel files are binary, and are most commonly used on platforms
where the distinction between binary and text is meaningful.
The OP would therefore be advised to use "wb" instead of "w".
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Apr 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
35578
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate),
2
13416
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to register for COM interop in Visual Studio So I go into Excel (where I want to use the object). Go to VB...
0
41186
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created an excel document which the user can see (at this stage of development) and passed some data to it. I then used the savas method to save the file. Again this seems to work as the file is created. However once I close the excel file and try and...
2
1818
by: JM | last post by:
Hi I have created a Windows Form that takes input. When the Run button is pressed the form is disabled and the code checks some files and inputs the data into an Excel worksheet (that is hidden so that I cannot watch as it gets filled up). When it is done it saves the Excel file. I find that if I go into another program while it's trying to work on the Excel spreadsheet that not all of the data appears (missing data!). If I click...
1
4107
by: Vlad | last post by:
I am trying to decide whether I should buy Visual Basic.NET Standard. I’d like to know the answer to the following questions to help me decide 1. Can I use Visual Basic.NET Standard to create a spreadsheet program? I don’t need all the functionality of Excel (other than some formatting, using some formulas, adding/deleting rows/cells, and printing) 2. Would someone that has Excel be able to open a spreadsheet created in my program ...
10
8213
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied everything I can find on COM Interop and .NET. I've also tried many of the 'Walkthroughs' on the MSDN site relating to COM add-ins, .NET and Office XP but am unable to get even these working in Excel 2002 or Word 2002. I've installed the Office XP...
0
1913
by: kennedystephen | last post by:
This seems like a simple task. But it's kicking my butt. I have 1 existing excel file. I want to copy the first 50 rows from that excel file, and put them in a new excel file. Then I want to get the next 50 rows of the existing document, and put them in another brand new excel file. The new excel documents cannot have named column headers. I want to keep getting 50 rows "chunks" from the existing file, and putting them into seperate, new...
1
2913
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert button. Once pulling down the drive list and clicking to the specific drive, folders will be shown in the dir list. When clicking the folders in the dir list, files in that certain folder should apprear in the file list, but this program should limit...
1
4763
by: barry.zhao | last post by:
Hi, I have a python program that constantly updates an excel spreadsheet. I would like to be able to view its updates while using excel to edit other excel files. Below are the test codes I have: -------------------------------------------------------------------------------------- from time import sleep import win32com.client as w32c
0
9781
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10836
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9567
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.