ספריית קוד פתוח .NET לקריאת גיליונות אלקטרוניים של Excel  

ExcelDataReader מאפשר לך לקרוא פורמטים של קבצים של Microsoft Excel באמצעות C#.

ExcelDataReader הוא API קל משקל בקוד פתוח שנכתב ב-C# לקריאת קבצי Microsoft Excel. באמצעות ה-API תוכל לקרוא Microsoft XLS, XLSX ו-CSV בקלות. ה-API תומך בגרסאות ישנות יותר של קובצי XLS בחזרה ל-Excel 2.0, תומך בתאריכי טקסט, ערכי נוסחאות במטמון ובנתיבי גיליון ריקים ב-XLSX.

יתרה מזאת, ה-API תומך בקידוד חלופי ב-XLS ובטיפול גמיש יותר בשם עמודות במערכים נתונים. זה קל להגדיר וזמין ב-NuGet.

Previous Next

תחילת העבודה עם ExcelDataReader

הדרך המומלצת להתקין את ExcelDataReader היא מ-NuGet, אנא השתמש בפקודה הבאה להתקנה מהירה יותר.

התקן את ExcelDataReader מ-NuGet

 Install-Package ExcelDataReader -Version 3.6.0

קרא קבצי Excel באמצעות .NET API

ExcelDataReader מאפשר למפתחי C# .NET לקרוא קבצי Microsoft Excel בקלות וביעילות. שיטת ההרחבה AsDataSet() היא מסייעת נוחה לקבלת הנתונים במהירות. IExcelDataReader מרחיב את ממשקי System.Data.IDataReader ו-IDataRecord כדי לנווט ולאחזר נתונים ברמה נמוכה יותר.

כותרת קריאה וכותרת Excel קבצים באמצעות C.NET

sing System;
using System.Text;
namespace ExcelDataReader.Core.BinaryFormat
{
    /// 
    /// Represents a string value of a header or footer.
    /// 
    internal sealed class XlsBiffHeaderFooterString : XlsBiffRecord
    {
        private readonly IXlsString _xlsString;
        internal XlsBiffHeaderFooterString(byte[] bytes, uint offset, int biffVersion)
            : base(bytes, offset)
        {
            if (biffVersion < 8)
                _xlsString = new XlsShortByteString(bytes, offset + 4);
            else if (biffVersion == 8)
                _xlsString = new XlsUnicodeString(bytes, offset + 4);
            else
                throw new ArgumentException("Unexpected BIFF version " + biffVersion, nameof(biffVersion));
        }
        /// 
        /// Gets the string value.
        /// 
        public string GetValue(Encoding encoding)
        {
            return _xlsString.GetValue(encoding);
        }
    }
}

ספרי בישול מוגנים באמצעות .NET API

הקוד הפתוח .NET API ExcelDataReader מאפשר לך גם לקרוא מסמכי Microsoft Excel המוגנים בסיסמה. אתה יכול לקרוא קבצים המוגנים באמצעות סיסמה באמצעות הגדרת הסיסמה בתצורת ExcelReaderConfiguration ולפתוח אותה באמצעות שיטת CreateOpenXmlReader() .

כיצד ליישם עיצובים כדי Spreadsheet תאים דרך C API

// Use the following code to Access your protected Spreadsheet file 
var conf = new ExcelReaderConfiguration { Password = "yourPassword" };
excelReader = ExcelReaderFactory.CreateOpenXmlReader(excelStream, conf);

App פורמט Excel Spreadsheet תאים באמצעות C

ספריית קוד פתוח ExcelDataReader מאפשרת למתכנתים ליישם עיצוב לתאי Excel שלהם עם רק כמה שורות של קוד C. לידיעתך, ExcelDataReader אינו תומך בתכונות עיצוב ישירות. עליך לאחזר את מספר התא המכיל את מחרוזת התבנית ולהשתמש בספריית ExcelNumberFormat צד שלישי למטרות עיצוב. הדוגמאות הבאות יעזרו לך להבין איך להשיג את זה.

כיצד ליישם עיצובים כדי Spreadsheet תאים דרך C API

string GetFormattedValue(IExcelDataReader reader, int columnIndex, CultureInfo culture)
{
    var value = reader.GetValue(columnIndex);
    var formatString = reader.GetNumberFormatString(columnIndex);
    if (formatString != null)
    {
        var format = new NumberFormat(formatString);
        return format.Format(value, culture);
    }
    return Convert.ToString(value, culture);
}
 עִברִית