麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

C#生成DBF文件

2019-11-17 02:13:35
字體:
供稿:網(wǎng)友

C#生成DBF文件

C# 生成DBF,無需注冊(cè)Microsoft.Jet.OLEDB。

 1 namespace Consoleapplication 2 { 3     class PRogram 4     { 5         static void Main(string[] args) 6         { 7             Test(); 8             Console.ReadKey(); 9         }10 11         private static void Test()12         {13             string testPath = AppDomain.CurrentDomain.BaseDirectory;14             var odbf = new DbfFile(Encoding.GetEncoding(936));15             odbf.Open(Path.Combine(testPath, "test.dbf"), FileMode.Create);16 17             //創(chuàng)建列頭18             odbf.Header.AddColumn(new DbfColumn("編號(hào)", DbfColumn.DbfColumnType.Character, 20, 0));19             odbf.Header.AddColumn(new DbfColumn("名稱", DbfColumn.DbfColumnType.Character, 20, 0));20             odbf.Header.AddColumn(new DbfColumn("地址", DbfColumn.DbfColumnType.Character, 20, 0));21             odbf.Header.AddColumn(new DbfColumn("時(shí)間", DbfColumn.DbfColumnType.Date));22             odbf.Header.AddColumn(new DbfColumn("余額", DbfColumn.DbfColumnType.Number, 15, 3));23 24             var orec = new DbfRecord(odbf.Header) { AllowDecimalTruncate = true };25             List<User> list = User.GetList();26             foreach (var item in list)27             {28                 orec[0] = item.UserCode;29                 orec[1] = item.UserName;30                 orec[2] = item.Address;31                 orec[3] = item.date.ToString("yyyy-MM-dd HH:mm:ss");32                 orec[4] = item.money.ToString();33                 odbf.Write(orec, true);34             }35             odbf.Close();36         }37     }38 39     public class User40     {41         public string UserCode { get; set; }42         public string UserName { get; set; }43         public string Address { get; set; }44         public DateTime date { get; set; }45         public decimal money { get; set; }46 47         public static List<User> GetList()48         {49             List<User> list = new List<User>();50             list.Add(new User() { UserCode = "A1", UserName = "張三", Address = "上海楊浦", date = DateTime.Now, money = 1000.12m });51             list.Add(new User() { UserCode = "A2", UserName = "李四", Address = "湖北武漢", date = DateTime.Now, money = 31000.008m });52             list.Add(new User() { UserCode = "A3", UserName = "王子龍", Address = "陜西西安", date = DateTime.Now, money = 2000.12m });53             list.Add(new User() { UserCode = "A4", UserName = "李三", Address = "北京", date = DateTime.Now, money = 3000.12m });54             return list;55         }56     }57 58 }

生成的文件截圖:

操作DBF文件的部分代碼:

  1 ///  2 /// Author: Ahmed Lacevic  3 /// Date: 12/1/2007  4 /// Desc:   5 ///   6 /// Revision History:  7 /// -----------------------------------  8 ///   Author:  9 ///   Date: 10 ///   Desc: 11  12  13 using System; 14 using System.Collections.Generic; 15 using System.Text; 16 using System.IO; 17 using System.Globalization; 18  19  20 namespace SocialExplorer.IO.FastDBF 21 { 22  23     /// <summary> 24     /// Use this class to create a record and write it to a dbf file. You can use one record object to write all records!! 25     /// It was designed for this kind of use. You can do this by clearing the record of all data  26     /// (call Clear() method) or setting values to all fields again, then write to dbf file.  27     /// This eliminates creating and destroying objects and optimizes memory use. 28     ///  29     /// Once you create a record the header can no longer be modified, since modifying the header would make a corrupt DBF file. 30     /// </summary> 31     public class DbfRecord 32     { 33  34         /// <summary> 35         /// Header provides information on all field types, sizes, precision and other useful information about the DBF. 36         /// </summary> 37         private DbfHeader mHeader = null; 38  39         /// <summary> 40         /// Dbf data are a mix of ASCII characters and binary, which neatly fit in a byte array. 41         /// BinaryWriter would esentially perform the same conversion using the same Encoding class. 42         /// </summary> 43         private byte[] mData = null; 44  45         /// <summary> 46         /// Zero based record index. -1 when not set, new records for example. 47         /// </summary> 48         private int mRecordIndex = -1; 49  50         /// <summary> 51         /// Empty Record array reference used to clear fields quickly (or entire record). 52         /// </summary> 53         private readonly byte[] mEmptyRecord = null; 54  55  56         /// <summary> 57         /// Specifies whether we allow strings to be truncated. If false and string is longer than we can fit in the field, an exception is thrown. 58         /// </summary> 59         private bool mAllowStringTruncate = true; 60  61         /// <summary> 62         /// Specifies whether we allow the decimal portion of numbers to be truncated.  63         /// If false and decimal digits overflow the field, an exception is thrown. 64         /// </summary> 65         private bool mAllowDecimalTruncate = false; 66  67         /// <summary> 68         /// Specifies whether we allow the integer portion of numbers to be truncated. 69         /// If false and integer digits overflow the field, an exception is thrown. 70         /// </summary> 71         private bool mAllowIntegerTruncate = false; 72  73  74         //array used to clear decimals, we can clear up to 40 decimals which is much more than is allowed under DBF spec anyway. 75         //Note: 48 is ASCII code for 0. 76         private static readonly byte[] mDecimalClear = new byte[] {48,48,48,48,48,48,48,48,48,48,48,48,48,48,48, 77                                                                48,48,48,48,48,48,48,48,48,48,48,48,48,48,48, 78                                                                48,48,48,48,48,48,48,48,48,48,48,48,48,48,48}; 79  80  81         //Warning: do not make this one static because that would not be thread safe!! The reason I have  82         //placed this here is to skip small memory allocation/deallocation which fragments memory in .net. 83         private int[] mTempIntVal = { 0 }; 84  85  86         //Ascii Encoder 87         private readonly Encoding encoding = Encoding.ASCII; 88  89         /// <summary> 90         /// Column Name to Column Index map 91         /// </summary> 92         private readonly Dictionary<string, int> mColNameToConIdx = new Dictionary<string, int>(StringComparer.InvariantCulture); 93  94  95  96         /// <summary> 97         ///  98         /// </summary> 99         /// <param name="oHeader">Dbf Header will be locked once a record is created 100         /// since the record size is fixed and if the header was modified it would corrupt the DBF file.</param>101         public DbfRecord(DbfHeader oHeader)102         {103             mHeader = oHeader;104             mHeader.Locked = true;105 106             //create a buffer to hold all record data. We will reuse this buffer to write all data to the file.107             mData = new byte[mHeader.RecordLength];108             mEmptyRecord = mHeader.EmptyDataRecord;109             encoding = oHeader.encoding;110 111             for (int i = 0; i < oHeader.mFields.Count; i++)112                 mColNameToConIdx[oHeader.mFields[i].Name] = i;113         }114 115 116         /// <summary>117         /// Set string data to a column, if the string is longer than specified column length it will be truncated!118         /// If dbf column type is not a strin
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲国产精品久久久久 | 国产艳妇av视国产精选av一区 | 天天躁狠狠躁夜躁2020挡不住 | 久久99精品久久久久久园产越南 | 性爱免费在线视频 | 欧美视频一区二区三区在线观看 | 国产免费人做人爱午夜视频 | 在线成人一区二区 | 一色桃子av大全在线播放 | 日韩毛片一区二区三区 | 黑人三级毛片 | 中文字幕 欧美 日韩 | 欧美14一15sex性hd | 在线播放中文 | 欧美成人免费在线视频 | 黄色av免费电影 | 911色_911色sss主站色播 | 久久久久久麻豆 | 在线观看国产www | 国产高潮好爽好大受不了了 | 好吊色欧美一区二区三区四区 | 久久黄色影院 | 亚洲成人福利在线观看 | 在线成人av观看 | 日本在线免费观看视频 | 一区国产在线观看 | 麻豆视频免费网站 | 激情夜色 | 国产精品嘿咻嘿咻在线播放 | 久久精品99国产国产精 | 亚洲日本欧美 | 国产精品久久久久久久久久久天堂 | 日本不卡一区二区三区在线观看 | 欧美亚洲黄色 | 欧美日韩精品一区二区三区不卡 | 在线亚洲免费 | 久久成人激情视频 | 精品国产一区三区 | 欧美爱爱一区二区 | 永久免费av在线 | 日本xxxx色视频在线观看免费, |