Results 1 to 3 of 3

Thread: save data to excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    save data to excel

    hello!
    how would i save the data in excel file like these:
    if i have this .xls file for example info.xls.

    NAME ID
    benjo 001
    mykel 002
    . .
    . .
    . .


    pls.

  2. #2
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: save data to excel

    Here are a couple of examples of using Excel with C#:

    This example sends a value to cell A1 of a Microsoft Office Excel 2003 worksheet.

    Code:
    public void EchoStringToCell(string str)
    {
        Excel.Worksheet sheet1 =
            (Excel.Worksheet)this.ThisApplication.Sheets.get_Item(1);
        ((Excel.Range)sheet1.Cells[1,1]).Value2 = str;
    }
    This example uses the Add method of the ChartObjects collection to add a chart to a Microsoft Office Excel 2003 worksheet programmatically.


    Code:
    public void CreateChart()
    {
        Excel.Worksheet thisWorksheet;
        thisWorksheet = thisWorkbook.ActiveSheet as Excel.Worksheet;
        Excel.ChartObjects charts = 
            (Excel.ChartObjects)thisWorksheet.ChartObjects(Type.Missing);
    
        // Adds a chart at x = 100, y = 300, 500 points wide and 300 tall.
        Excel.ChartObject chartObj = charts.Add(100, 300, 500, 300);
        Excel.Chart chart = chartObj.Chart;
    
        // Gets the cells that define the bounds of the data to be charted.
        Excel.Range chartRange = thisWorksheet.get_Range("A5","D8");
        chart.SetSourceData(chartRange,Type.Missing);
    
        chart.ChartType = Excel.XlChartType.xlXYScatter;
        Excel.SeriesCollection seriesCollection= 
            (Excel.SeriesCollection)chart.SeriesCollection(Type.Missing);
        Excel.Series series = seriesCollection.Item(seriesCollection.Count);
    }
    This example requires:
    Data to be charted, stored in the range from A5 to D8 in the worksheet.

    Not sure if this is what you were looking for.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: save data to excel

    i think it's hard to do appending data to excel file,
    if possible i could write it on text file or CSV file just like this:

    NAME ID
    name1 001
    name2 002

    tnx to u

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width