pinoyz

hi there...... hi i have a problem regarding saving i saw some example here it seem's ok..... but i want is to gather the data from datagridview and save it into excel file... here's the example which we can save using richtextbox

Private Sub SaveFile(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim x As New SaveFileDialog
x.Title = "Save Rich Text File"
x.Filter = "RTF Files|*.rtf"
If x.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.RichTextBox1.SaveFile(x.FileName)
End If
End Sub
End Class

in this example only rtf file perfectly save but when i change it into excel there's a bunch of garbarge before my data/text..... can some one help me regarding into this manner... much appreciated save into excel which data cam from datagrid




Re: Visual Basic Express Edition saving file into excel problem

Bruno Yu - MSFT

pinoyz,

Since your code saves the rtf file, why don't you change the .rtf into .xls and save the x.FileName Is that possible Or you can also import data from rtf file into xls file.

Another way, please read this article: How To Query and Display Excel Data by Using ASP.NET, ADO.NET, and Visual Basic .NET.

http://support.microsoft.com/kb/311731

I hope this can help you, too.






Re: Visual Basic Express Edition saving file into excel problem

Dave299

You could write the data from your grid into a csv file, which you could then open in Excel without any problems.



Re: Visual Basic Express Edition saving file into excel problem

js06

Where you able to get it to save as .xls   






Re: Visual Basic Express Edition saving file into excel problem

pinoyz

thx.... for the replies...

in richtextbox i used Me.RichTextbox1.savefile(x.filename) how about in datagridview i can't figure it out....






Re: Visual Basic Express Edition saving file into excel problem

Bruno Yu - MSFT

pinoyz,

Since it is hard to save file directly as a xls format, I recommend you to save it as csv file, then open it in Excel. Or you can also try to import data from the rtf file, too.

Sometimes, if it is impossible to reach the target directly, why don't you consider to change another way with the same result So please have a try all the methods in the reply posts. :-)






Re: Visual Basic Express Edition saving file into excel problem

pinoyz

ok i'll try, sorry for trouble...... coz my boss want me to finish the program ASAP... that's why i'm keeping posting..... sorry about that...




Re: Visual Basic Express Edition saving file into excel problem

Bruno Yu - MSFT

pinoyz,

I often see your posts in MSDN forum, you are active in asking problems and positive to solve. I recommend you to learn some knowledge on VSTO (Visual Studio Tool for Office). Then you will have many idears on the Office issue when developing .NET applications.

Thank you for all the questions and keep working hard. I wish your project can be fine under your management and hope that wee can keep in touch in this active forum. :-)






Re: Visual Basic Express Edition saving file into excel problem

js06

My only other suggestion to you would be to look into a program called Spreadsheet Gear for .net

I first started 3 years ago making spreadsheets and then last year i started using VBA in excel. At the end of last year i moved to VB.net after realizing that it is hard to control quite a few aspects of data security in excel. Then last week i found Spreadsheet Gear and it has basically replaced the datagridview for me. You can create your spreadsheets in excel and then import them into your form in VB and then happy coding.

The only thing you have to be careful of is that it doesn't support all the features of Excel but you can make up for what it lacks with the ease of developement it gives you. What took me 2 months to figure out with the datagridview, i created in about 2 days. It gives a more "literal" way to create and code.

If you start looking into VBA in Excel and learn some of the code with the help examples, you will be ready to move to Spreadsheet Gear. And best of all it saves your files as .xls with perfection.






Re: Visual Basic Express Edition saving file into excel problem

pinoyz

spreadsheet gear interesting.....it is an add-on

Regards

Pinoyz






Re: Visual Basic Express Edition saving file into excel problem

js06

Their website will tell you everything you need to know. It is both a stand-alone and an add-on.

If after you look it up and you talk to them you still have questions let me know. You can download a trial from their site.

Good luck.






Re: Visual Basic Express Edition saving file into excel problem

Rppoeht

wow I might be able to help here. I have tried to save a rich text box into another format other than rtf as well and noticed the extra garbage that you are talking about. This is what I did the elminate that extra stuff.

RichTextBox1.SaveFile("filename.extension", RichTextBoxStreamType.PlainText)

Adding that RichTextBoxStreamType.PlainText removed that extra junk





Re: Visual Basic Express Edition saving file into excel problem

pinoyz

thx... for the replies.....

i got another problem... how can we make columns of datagridview same as with excel in my code below the data of datagridview are in the same column of excel. how can we seperate it and also without merging.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connectionstring1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\pulloutneo.mdb;User Id=admin;Password=;")
        Dim sqlcom As New OleDb.OleDbCommand("select * from pullout", connectionstring1)
        Dim adapt As New OleDb.OleDbDataAdapter(sqlcom)
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim ss As New SaveFileDialog
        ss.Filter = "excel|*.htm"
        ss.CheckPathExists = True

        ss.Title = "save"
        ss.ShowDialog(Me)

        sqlcom.Connection.Open()
        adapt.Fill(ds)
        DataGridView1.DataSource = dt
        Try
                        ds.Tables.Add(dt)
            ds.WriteXml(ss.FileName)
        Catch ex As Exception

        End Try






Re: Visual Basic Express Edition saving file into excel problem

js06

pinoyz,

i see that you have quite a few questions relating to excel, check out this post. I think this may help.

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1279113&SiteID=1






Re: Visual Basic Express Edition saving file into excel problem

pinoyz

thx man.... it's cool.....is it free for vbee