473,396 Members | 2,036 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,396 software developers and data experts.

Creating an Excel document from .NET + C#

Hi all,

In an effort to try to impress the boss, I would like to log accounting information to an Excel spreadsheet using C# and .NET. This would be a mockup only, not a real solution - yet!

We are a small ticketing company - not a bunch of IT whiz kids. ...but I do have an IT background.

I have been successful in logging (printing) tickets to a word document, and it all works kinda cool.
However, I wish to log to same information to an Excel document. For example, I want to log each ticket on a new row of a spreadsheet. Alas, writing to an excel document is not as easy as writing to Word.

So I would need to (1) create a new Excel document, if it did not exist, (2) Write the ticket information on the NEXT row of a spreadsheet, (3) Save and close the file. I am looking at writing a new function/method called "public void Log" to do this.

How would I do this? Can someone provide an example of how to create and save a new Excel document? And then write data to the rows?

Thankyou so very much in advance!

Ticketing printing code using .NET and C#:

class Ticket

{

public Event e;

public String Section;

public String Type;

public String Price;

public String Comment;



private Word.ApplicationClass WordApp = null;

private Word.Document Paper = null;



public void Open()

{

if (WordApp == null)

{

object Missing = System.Reflection.Missing.Value;

object FileName = "normal.dot";

object NewTemplate = false;

object DocType = 0;

object isVisible = true;



WordApp = new Word.ApplicationClass();

Paper = WordApp.Documents.Add(ref FileName, ref NewTemplate, ref DocType, ref isVisible);



WordApp.Visible = true;



Paper.Activate();

}



return;

}



public void Close()

{

if (WordApp != null)

{

object Missing = System.Reflection.Missing.Value;

object FileName = "ticket.doc";



Paper.SaveAs(ref FileName, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);



Paper.Close(ref Missing, ref Missing, ref Missing);

WordApp.Quit(ref Missing, ref Missing, ref Missing);



WordApp = null;

}



return;

}



public void Print()

{

if (WordApp != null)

{

WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;

WordApp.Selection.Font.Bold = (int) Word.WdConstants.wdToggle;

WordApp.Selection.TypeText("Ticket Information");



InsertBlankLines(1);



WordApp.Selection.Font.Bold = (int) Word.WdConstants.wdToggle;

WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;

WordApp.Selection.TypeText("\nEvent:\t" + e.Name);

WordApp.Selection.TypeText("\nTheatre:\t" + e.Venue);

WordApp.Selection.TypeText("\nDate:\t" + e.DateAndTime);

WordApp.Selection.TypeText("\nSection:\t" + Section);

WordApp.Selection.TypeText("\nType:\t" + Type); WordApp.Selection.TypeText("Price:\t" + Price);

WordApp.Selection.TypeText("\nAdditional Information: " + Comment);

WordApp.Selection.TypeText("\nDate Printed:\t"); InsertTimeDate();



InsertBlankLines(2);

}



return;

}



private void InsertBlankLines(int number)

{

if (WordApp != null)

{

int iCount = 0;



for (iCount = 0; iCount < number; ++iCount)

{

WordApp.Selection.TypeParagraph();

}

}



return;

}



private void InsertTimeDate()

{

if (WordApp != null)

{

object Missing = System.Reflection.Missing.Value;

object False = false;

object objDate = "dddd, MMMM dd, yyyy at HH:mm:ss";



WordApp.Selection.InsertDateTime(ref objDate, ref False, ref Missing, ref Missing, ref Missing);

WordApp.Selection.TypeParagraph();

}



return;

}

}

Nov 17 '05 #1
0 3923

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

Similar topics

1
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
6
by: Kerri McDonald | last post by:
We have an application where the user fills out many screens and when they are done, we are supposed to display the text they entered in a word or excel format. That is fairly easily accomplished...
5
by: Guy Incognito | last post by:
Hello, I've written an asp.net application that creates Excel documents. It works by creating an excel document in XML format. But I wonder if I'm reinventing the wheel. I know that there are...
9
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save...
6
by: Michael Groeger | last post by:
Hi, I have an aspx page which generates an excel document and transfers it to the browser as attachment. Normally, once the document is transferred the open save dialog prompts to open or save...
7
by: Paul | last post by:
Hi I have created an excel file download feature within a .net application using Microsoft Office XP primary interop assembly for excel. I was just wondering if anyone knows if you can also embed...
11
by: Andy Burchill | last post by:
Hi there, I am trying to find out what the best way of creating an excel spreadsheet is, this will need to be done dynamically by an aspx website on the server side. The main way would be to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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 project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.