473,396 Members | 1,997 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.

Writing to Files

Can I write to files, say for example, to an excel spreadsheet and have it
written in a certain order or in certain cells?

Thanks,
VAL
Jul 17 '05 #1
2 6706
On Tue, 30 Sep 2003 05:55:16 -0400, "Nevo" <vi*********@bellsouth.net>
wrote:
Can I write to files, say for example, to an excel spreadsheet and have it
written in a certain order or in certain cells?


Yes, it is possible.

You need to create a reference to the Excel object in your program. In
the Visual Basic editor, select menu Project | References and scroll
down and tick Microsoft Excel, click OK.

Here's a simple program that writes values to all cells in the range
A1:J10 in a new spreadsheet. It then save the new spreadsheet.

Private Sub cmdCommit_Click()

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add

For i = 1 To 10
For j = 1 To 10
xlSheet.cells(i, j) = i * j
Next j
Next i

xlBook.SaveAs ("c:\temp\VBSheet1.xls")

End Sub

Jul 17 '05 #2
To write to an excel spreadsheet, you need excel installed on the system.

Here is some code for you:

' Need to add Component "Microsoft Excel 9.0 Object Library"
' Declare object variables for Microsoft Excel,
' application workbook, and worksheet objects.

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

' Assign object references to the variables. Use
' Add methods to create new workbook and worksheet
' objects.

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add

' Assign the values Fron double Matrix ExportData to
' Microsoft Excel cells.
Dim DataStartAtRow As Integer

xlApp.DisplayAlerts = False

'To set a singel cell>
xlSheet.Cells(1, 1).value = "Hello world!"

'To transfer a vector
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(5,5)) = myMatrix5x5

' Use the Formula method to add the values in
' Microsoft Excel.
' xlSheet.Cells(3, 1).Formula = "=R1C1 + R2C1"

' Save the Worksheet.
xlSheet.SaveAs exportFileName
' Close the Workbook
xlBook.Close
' Close Microsoft Excel with the Quit method.
xlApp.Quit

' Release the objects.
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing

Good luck!

/Andreas Lundgren - Sweden

"Nevo" <vi*********@bellsouth.net> wrote in message news:<As******************@bignews4.bellsouth.net> ...
Can I write to files, say for example, to an excel spreadsheet and have it
written in a certain order or in certain cells?

Thanks,
VAL

Jul 17 '05 #3

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

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
10
by: Neil Trigger | last post by:
Is there a way of creating a seperate text file on a server every time a form is sent? -- ¿ Trigger ? http://www.magic2k.com/ http://www.oddmap.co.uk
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
12
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in programming so you'll have to bear with me... My...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
3
by: Adonis Vargas | last post by:
I am writing a program that walks a directory full of mp3s reads their ID3 data (using Mutagen), this part works perfectly. The problem is I write these tags to a CSV file through the CSV module....
3
by: koutoo | last post by:
I have a code that writes to 2 seperate files. I keep getting a "list index out of range" error. The strange part is that when checking the files that I'm writing too, the script has already...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
2
by: as001 | last post by:
Hi, I'm writing a windows application in C# using VS 2003. I got stuck where it has to write multiple output text files. Here's my piece of code: for loop { Random r = new Random();...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.