簡體   English   中英

文件,Excel概念在C#控制台應用程序中

[英]file,excel concept in C# console application

我的txt文件包含

empno name  salary
101   lekha  20000
102   hema   30000

我想更改102-hema的工資,這可能改變嗎? 。如何改變。

我再次想使用C#控制台應用程序將數據存儲,檢索,更新到excel中

using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text; 

namespace Excelcalling1
{
    class Program
    {
        static void Main(string[] args)
        {
            string F1Name = "C:\\Documents and Settings\\origin\\Desktop\\New Folder\\Book1.xls";
            string CnStr = ("Provider=Microsoft.Jet.OLEDB.4.0;" + ("Data Source="    
            + ( F1Name + (";" + "Extended Properties=\"Excel 8.0;\""))));

            DataSet ds = new DataSet();
            OleDbDataAdapter DA = new OleDbDataAdapter("Select * from [Sheet1$]", CnStr);                         
            Console.WriteLine("File Accessed!!!!");                                                 

            try
            { 
                DA.Fill(ds, "srlno");
                foreach (DataRow dr in ds.Tables["srlno"].Rows)
                {                        
                    Console.WriteLine(dr["A"] + "\t" + dr["B"] + "\t" + dr["C"]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }  
    }
}

您可以將其導入excel並查詢此信息。 或者有一個txt odbc驅動程序,您可以使用該外觀@ http://www.c-sharpcorner.com/UploadFile/mahesh/AccessTextDb12052005071306AM/AccessTextDb.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM