godsharp - Hsu.Db.Export.Spreadsheet 2024.410.14-preview141602

A component that regularly exports database tables to spreadsheets every day, can export Excel and Csv files, and supports Excel templates.

PM> Install-Package Hsu.Db.Export.Spreadsheet -Version 2024.410.14-preview141602 -Source https://www.myget.org/F/godsharp/api/v3/index.json

Copy to clipboard

> nuget.exe install Hsu.Db.Export.Spreadsheet -Version 2024.410.14-preview141602 -Source https://www.myget.org/F/godsharp/api/v3/index.json

Copy to clipboard

> dotnet add package Hsu.Db.Export.Spreadsheet --version 2024.410.14-preview141602 --source https://www.myget.org/F/godsharp/api/v3/index.json

Copy to clipboard
<PackageReference Include="Hsu.Db.Export.Spreadsheet" Version="2024.410.14-preview141602" />
Copy to clipboard
source https://www.myget.org/F/godsharp/api/v3/index.json

nuget Hsu.Db.Export.Spreadsheet  ~> 2024.410.14-preview141602
Copy to clipboard

> choco install Hsu.Db.Export.Spreadsheet --version 2024.410.14-preview141602 --source https://www.myget.org/F/godsharp/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "godsharp" -SourceLocation "https://www.myget.org/F/godsharp/api/v2"
Install-Module -Name "Hsu.Db.Export.Spreadsheet" -RequiredVersion "2024.410.14-preview141602" -Repository "godsharp" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following symbol server URL: https://www.myget.org/F/godsharp/api/v2/symbolpackage/


Hsu.Db.Export.Spreadsheet

dev preview main Nuke Build FreeSql OpenXml

A component that regularly exports database tables to spreadsheets every day, can export Excel and Csv files, and supports Excel templates.

Package Version

  • Hsu.Db.Export.Spreadsheet : library
  • Hsu.Db.Export.Spreadsheet.Hosting : template
Name Source Stable Preview
Hsu.Db.Export.Spreadsheet Nuget NuGet NuGet
Hsu.Db.Export.Spreadsheet MyGet MyGet MyGet
Hsu.Db.Export.Spreadsheet.Hosting Nuget NuGet NuGet
Hsu.Db.Export.Spreadsheet.Hosting MyGet MyGet MyGet

Getting Started

Install Packages

  • Hsu.Db.Export.Spreadsheet
  • FreeSql

Configure DependencyInjection

static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
    services.AddDailySyncSpreadsheet();
    ConfigureFreeSql(services, configuration);
}

static void ConfigureFreeSql(IServiceCollection services, IConfiguration configuration)
{
    var freeSql = new FreeSqlBuilder()
        .UseConnectionString(DataType.MySql, configuration.GetConnectionString("Default"))
        .Build();

    freeSql.Aop.CommandAfter += (_, e) =>
    {
        if (e.Exception != null)
        {
            Log.Logger.Error("Message:{Message}\r\nStackTrace:{StackTrace}", e.Exception.Message, e.Exception.StackTrace);
        }

        Log.Logger.Debug("FreeSql>A>{Sql}", e.Command.CommandText);
    };
    
    freeSql.Aop.CommandBefore += (_, e) =>
    {
        Log.Logger.Debug("FreeSql>B>{Sql}", e.Command.CommandText);
    };

    services.AddSingleton(freeSql);
}

Add Export Options

  • Update ConnectionString
  • Update Export Options

Template only support Excel export

{
  "ConnectionStrings": {
    "Default": "Data Source=mysql.sqlpub.com;Port=3306;User ID=public;Initial Catalog=db_hsu_des;Charset=utf8;SslMode=none;Min pool size=1"
  },
  "Export": {
    "Spreadsheet": {
      "Trigger": "00:00:00",
      "Launch": true,
      "Interval": "00:00:30",
      "Timeout": "00:01:30",
      "Path": null,
      "Tables": [
        {
          "Name": "Employees",
          "Code": "employees",
          "Filter": "create_at",
          "Chunk": 5000,
          "AscOrder": true,
          "Output": "Csv",
          "Fields": [
            {
              "Name": "EmployeeNo",
              "Column": "emp_no",
              "Type": "Int32"
            },
            {
              "Name": "Birthdate",
              "Column": "birth_date",
              "Type": "DateTime",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "First Name",
              "Column": "first_name",
              "Type": "String"
            },
            {
              "Name": "Last Name",
              "Column": "last_name",
              "Type": "String"
            },
            {
              "Name": "Gender",
              "Column": "gender",
              "Type": "String",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "Hire Date",
              "Column": "hire_date",
              "Type": "DateTime",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "Create At",
              "Column": "create_at",
              "Type": "DateTime"
            }
          ]
        },
        {
          "Name": "Titles",
          "Code": "titles",
          "Filter": "create_at",
          "Chunk": 5000,
          "AscOrder": true,
          "Output": "Xlsx",
          "Fields": [
            {
              "Name": "EmployeeNo",
              "Column": "emp_no",
              "Type": "Int32"
            },
            {
              "Name": "Title",
              "Column": "title",
              "Type": "String"
            },
            {
              "Name": "From Date",
              "Column": "from_date",
              "Type": "DateTime",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "To Date",
              "Column": "to_date",
              "Type": "DateTime",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "Create At",
              "Column": "create_at",
              "Type": "DateTime"
            }
          ]
        },
        {
          "Name": "Salaries",
          "Code": "salaries",
          "Filter": "create_at",
          "Chunk": 5000,
          "AscOrder": false,
          "Template": "ExportTemplate.xlsx",
          "Output": "Xlsx",
          "Fields": [
            {
              "Name": "EmployeeNo",
              "Column": "emp_no",
              "Property": "EmployeeNo",
              "Type": "Int32"
            },
            {
              "Name": "Salary",
              "Column": "salary",
              "Property": "Salary",
              "Type": "Int32",
              "Format": "0000.00"
            },
            {
              "Name": "From Date",
              "Column": "from_date",
              "Property": "FromDate",
              "Type": "DateTime",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "To Date",
              "Column": "to_date",
              "Property": "ToDate",
              "Type": "DateTime",
              "Format": "yyyy-MM-dd"
            },
            {
              "Name": "Create At",
              "Column": "create_at",
              "Type": "DateTime"
            }
          ]
        }
      ]
    }
  }
}
  • Worker
  • Trigger : The time to sync tables to local
  • Launch : if true will execute once at startup
  • Interval : The time to wait for export mutil days
  • Timeout : The time to wait for table read operations
  • Path : The path that export file storage
  • Tables
  • Name : The name of the column, to display in header
  • Code : The column of the table
  • Filter : The date column to filter
  • Chunk : The size of the chunk per read from the database
  • AscOrder : Is ascending or descending
  • Output : Only Csv and Xlsx
  • Fields
  • Property : The name of the property for object to export,if null use Column
  • Type : The type of field, default is String
  • Nullable : The field is nullable
  • Template : The template excel file,only Xlsx output
  • Format : The format for IFormattable
  • Escape : if true escape the value, default is false

Template Format

The template format is Field.

Fields Type Format

  • Boolean
  • Byte
  • Char
  • Int16
  • Int32
  • Int64
  • SByte
  • UInt16
  • UInt32
  • UInt64
  • Single
  • Double
  • Decimal
  • String
  • DateTime
  • Enum

License

MIT

  • .NETFramework 4.6.1
    • DocumentFormat.OpenXml (>= 2.20.0)
    • FreeSql (>= 3.2.698)
    • Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
    • Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
    • Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
  • .NETFramework 4.6.2
    • DocumentFormat.OpenXml (>= 2.20.0)
    • FreeSql (>= 3.2.698)
    • Microsoft.Extensions.Configuration.Binder (>= 7.0.0)
    • Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
    • Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
  • .NETStandard 2.1
    • DocumentFormat.OpenXml (>= 2.20.0)
    • FreeSql (>= 3.2.698)
    • Microsoft.Extensions.Configuration.Binder (>= 7.0.0)
    • Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
    • Microsoft.Extensions.Logging.Abstractions (>= 7.0.0)
  • .NETFramework 4.6.1: 4.6.1.0
  • .NETFramework 4.6.2: 4.6.2.0
  • .NETStandard 2.1: 2.1.0.0

Owners

Seay

Authors

Hsu

Project URL

https://github.com/hsu-net/db-export-spreadsheet

License

Unknown

Tags

Database Db Export Excel Csv Spreadsheet Hsu

Info

51 total downloads
6 downloads for version 2024.410.14-preview141602
Download (83.25 KB)
Download symbols (33.23 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
2024.410.14-preview141602 83.25 KB Mon, 14 Oct 2024 06:16:14 GMT 6
2024.410.12 82.57 KB Sat, 12 Oct 2024 03:31:18 GMT 5
2023.307.24 81.33 KB Mon, 24 Jul 2023 15:41:53 GMT 5
2023.307.24-preview233257 81.42 KB Mon, 24 Jul 2023 15:33:20 GMT 1
2023.307.24-preview231341 81.4 KB Mon, 24 Jul 2023 15:14:07 GMT 6
2023.307.24-preview225237 81.42 KB Mon, 24 Jul 2023 14:52:54 GMT 1
2023.307.24-preview223238 81.4 KB Mon, 24 Jul 2023 14:32:57 GMT 2
2023.307.24-preview190932 81.42 KB Mon, 24 Jul 2023 11:09:47 GMT 3
2023.307.24-preview124145 81.05 KB Mon, 24 Jul 2023 04:42:01 GMT 2
2023.307.19 54.93 KB Wed, 19 Jul 2023 15:40:56 GMT 3
2023.307.19-preview233935 55.04 KB Wed, 19 Jul 2023 15:39:50 GMT 6
2023.307.19-preview170052 51.11 KB Wed, 19 Jul 2023 09:01:09 GMT 5
2023.307.19-preview164935 50.95 KB Wed, 19 Jul 2023 08:49:49 GMT 6