GithubHelp home page GithubHelp logo

dotnetcore / magicodes.ie Goto Github PK

View Code? Open in Web Editor NEW
2.1K 74.0 472.0 147.66 MB

Import and export general library, support Dto import and export, template export, fancy export and dynamic export, support Excel, Csv, Word, Pdf and Html.

Home Page: http://docs.dotnet-china.com/Magicodes.IE

License: MIT License

C# 99.09% HTML 0.91%
import-and-export excel pdf word html magicodes csv html-word-pdf excel-sheet csharp

magicodes.ie's People

Contributors

1518648489 avatar 263613093 avatar afonsof91 avatar applebananamilk avatar barryyue avatar cacocode avatar ccccccmd avatar codelove1314 avatar dependabot[bot] avatar excalione avatar geffzhang avatar hueifeng avatar kamenriderkuuga avatar lemonnocry avatar linch90 avatar netty2019 avatar nivalxer avatar raymmond avatar serfend avatar sgalcheung avatar skywolf627 avatar stoning-code avatar tanyongzheng avatar wangj90 avatar wlclass avatar xiangxiren avatar xin-lai avatar xl-wenqiang avatar yachengmu avatar zyowee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magicodes.ie's Issues

导入带guid类型时报错

public class WeiChat_BrokerClient3 : WeiChat_WeChatWithNoKeyBase
{

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    /// <summary>
    ///   用户id
    /// </summary>
    [Display(Name = "用户ID")]
    public Guid userId { get; set; }

 。。。。。
}

}
执行的代码是
//导入数据

        var filePath = Path.Combine(Server.MapPath("~/upload"), "1.xlsx");

        var import = await Importer.Import<WeiChat_BrokerClient3>(filePath);
        import.ShouldNotBeNull();

1

2.1.0版本,从excel导入数据,不识别日期格式

Describe the bug
A clear and concise description of what the bug is.
excel中 列是日期格式,导入报错,提示“值 43914 无效,请填写正确的日期时间格式!”
To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
微信截图_20200325165247

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

excel导出报错

版本:1.4.21
excel导出时,如果导出模型定义了ExporterHeader就会报错,这是反编译的报错的位置:
image

[AutoMap(typeof(Standard))]//这是automap的映射配置
[ExcelImporter(IsLabelingError = true)]//这个模型同时也用于导出模板
public class ImportExcelDto
{
        public const int MaxLength = 1024;
        /// <summary>
        /// 规程类型
        /// </summary>
        [MaxLength(MaxLength)]
        [Display(Name = "名称")]
        [ExporterHeader("名称")]
        public string Name { get; set; }
}
//导出文件
await exporter.Export("xxxx.xlsx", new List<ImportExcelDto>{new ImportExcelDto{Name="123"}});

如果模型没有定义ExporterHeader则不会报错

在导出Excel时如何自定义复杂表头?

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

DataTable导出没有列名,这段代码将DataTable的属性与传入的DataTable列名比较导到获取不到列名

DataTable导出没有列名,这段代码将DataTable的属性与传入的DataTable数据列名比较导到获取不到列名

https://github.com/xin-lai/Magicodes.IE/blob/master/src/Magicodes.ExporterAndImporter.Excel/ExcelExporter.cs

///


/// 获取头部定义
///

///
///
///
///

`
private static bool GetExporterHeaderInfoList(out List exporterHeaderList,
DataColumnCollection dataColumns)
{
exporterHeaderList = new List();
var objProperties = typeof(T).GetProperties();
if (objProperties == null || objProperties.Length == 0)
return true;
var index = 0;
for (var k = 0; k < dataColumns.Count; k++)
for (var i = 0; i < objProperties.Length; i++)
if (dataColumns[k].ColumnName.Equals(objProperties[i].Name))
{
index += 1;
exporterHeaderList.Add(new ExporterHeaderInfo
{
Index = index,
PropertyName = objProperties[i].Name,
ExporterHeader =
(objProperties[i].GetCustomAttributes(typeof(ExporterHeaderAttribute), true) as
ExporterHeaderAttribute[])?.FirstOrDefault()
});
}
return false;
}

`

@xin-lai

支持根据配置导入导出

现在是根据Dto及对应属性控制导入,是否能支持根据配置信息导入,如根据配置JSON文件导入到DataTable。目前张队长已实现基于DataTable的导出。

生成模板时可否增加引用类型的获取,生成模板时的行为类似枚举

比如我们平常所说的商品类别,枚举比较适用于枚举值不多并且值比较固定场景。商品类别比较多,而且有时会有些改动,有没有办法在属性标注上建一个Action委托,从数据库获取所有的商品类别名称,这样生成模板时类别名称也可以像枚举值可以选择,方便用户使用也方便后台数据不会引用出错。

导出数据的数据头没有汉化

Importer.GenerateTemplate<ImportMonthSalaryDto>("salarytemplate.xlsx");

这样到出模板数据头汉化了

但是如果导出的数据,excel数据头没有汉化

IImporter Importer = new ExcelImporter();
 var result = await exporter.Export("newSalary.xlsx", dtos);

其中 dtos是ImportMonthSalaryDto的集合
image

表头问题

目前导出Excel时,会自动加入筛选功能
问题1、如何取消这个自动筛选功能
问题2、既然有了筛选功能,那为啥只支持10行呢?

我想要的解决方案是
筛选功能 需要我自己设置(可以加入到 ExporterAttribute 这个特性中 )
筛选行数也支持自己定义

导入模板能否生成一个Summary ,用于展示导入需要注意的一些要点

Is your feature request related to a problem? Please describe.
在日常导入中,需要有一个导入说明提供查看当前导入模板的使用方法或者注意事项
In the daily Excel import, there needs to be an import specification that provides the usage or considerations for viewing the current Excel import template

Describe the solution you'd like
能否在导入模板生成的时候 在导入模型上指定一个标签用于填写导入说明,
并将导入说明 填充到Excel Sheet的第一行或进行醒目的展示
Can you specify a label on the Excel import model to fill in the import instructions when the import template is generated?
Fill in the first row of the Excel Sheet with the import instructions or make them visible
Thanks U

如何把数字导出成文本?

Format 设置为什么 可以让 单元格 在导出后变成文本。
long 的 总变成 科学计数法
网上查了下 设成 @ 也没有用。。。
还是说最新版已经支持?

Out Of Memory

在使用导出excel功能的时候,刚开始导出,内存猛的上涨接近100M,导出结束后下降80+M,实际导出的excel才5M,随着不断重复这个导出操作,应用内存逐渐上升,几乎没结束一次导出,内存占用就多20M,请问有遇到这个问题吗?如何解决?

导出日期变成了数字

版本:1.4.21
导出的模型属性类型DateTime?类型,excel数据是数字,要手动设置单元格格式才能变成日期
image

请在文档中注明不支持Excel97-2003

using (var excelPackage = new ExcelPackage(stream))
这行代码读取xls的Excel时,Sheet的数量为0,后续报错无法操作,将文档格式改为xlsx后,此问题消失

导入标注问题

如果当前Excel上传模板上的某一个单元格有一个标注,再次在相同的单元格上写标注就会报错
image

需要处理这种情况吗?

一个DTO中有多个字段,如何选择让某些个字段不导出

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

nuget 安装Magicodes.IE.Excel 2.1.4,导入报错

var import = await _importer.Import(fullPath, "");
import.Exception :
Method not found: 'System.String Magicodes.ExporterAndImporter.Core.Extension.Extension.Save(System.Drawing.Image, System.String, System.Drawing.Imaging.ImageFormat)'.

clone最新的源码直接引用,没有异常,

对.NET版本有要求不?

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 无法安装程序包“Magicodes.IE.Excel 2.1.2”。你正在尝试将此程序包安装到目标为“.NETFramework,Version=v4.5”的项目中,但该程序包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请联系程序包作者。

TableStyles.None不生效

运行demo示例,dto类:

    [ExcelExporter(Name = "学生信息", AutoFitAllColumn = true, TableStyle = "None")]
    public class Student
    { 
        /// <summary> 
        /// 姓名 
        /// </summary> 
        [ExporterHeader(DisplayName = "姓名")] 
        public string Name { get; set; } 
        /// <summary> 
        /// 年龄 
        /// </summary> 
        [ExporterHeader(DisplayName = "年龄")] 
        public int Age { get; set; }
        /// <summary> 
        /// 备注 
        /// </summary> 
        [ExporterHeader(DisplayName = "备注")]
        public string Remarks { get; set; } 
        /// <summary> 
        /// 出生日期 
        /// </summary>
        [ExporterHeader(DisplayName = "出生日期", Format = "yyyy-MM-dd")] 
        public DateTime Birthday { get; set; } 
    }

TableStyle为None时对应于TableStyles.None,但是导出的excel样式是Medium9,如下图:
image

Asp.net core 3.1 WebAPI 调用 PdfExporter 报错

具体错误如下:
Could not load type 'Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine' from assembly 'Microsoft.AspNetCore.Razor.Language, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'."
按提示 添加 Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine 更新引用到3.1.2.0 也报错,不明白了!
但是.net core 3.1的测试项目确可以运行
感谢

亟需帮助!!

为了更好的完善Magicodes.IE,年前我会逐步重构和优化部分内容,同时急缺文档和翻译(将文档翻译为英文文档)支持,希望有朋友能够参与进来。

添加并重构当前特性

  • 支持使用System.ComponentModel.DataAnnotations命名空间下的部分特性来控制导入导出,比如
    • DisplayAttribute
    • DisplayFormatAttribute
    • DescriptionAttribute
  • 封装简单的易于使用的单一特性,例如
    • IEIgnoreAttribute(可作用于属性、枚举成员,可影响导入和导出)

2.2.0-beta2版本以Append方式导出多个sheet时,发生“Tablename is not unique”错误

2.2.0-beta2版本以Append方式导出多个sheet时,当Append的ICollection均为空集合时,报 “Tablename is not unique”错误,比如:

new ExcelExporter().Append(new List<Student>()).Append(new List<Teacher>()).ExportAppendData("test.xlsx");

image

详细错误信息如下:

System.ArgumentException
  HResult=0x80070057
  Message=Tablename is not unique
  Source=EPPlus
  StackTrace:
   at OfficeOpenXml.Table.ExcelTableCollection.Add(ExcelAddressBase Range, String Name)
   at Magicodes.ExporterAndImporter.Excel.Utility.ExportHelper`1.AddHeader()
   at Magicodes.ExporterAndImporter.Excel.Utility.ExportHelper`1.AddHeaderAndStyles()
   at Magicodes.ExporterAndImporter.Excel.Utility.ExportHelper`1.Export(ICollection`1 dataItems)
   at Magicodes.ExporterAndImporter.Excel.ExcelExporter.Append[T](ICollection`1 dataItems)
   at Magicodes.IE.Excel.Program.Export() in E:\Technology\Magicodes.IE.Excel\Magicodes.IE.Excel\Program.cs:line 29
   at Magicodes.IE.Excel.Program.Main(String[] args) in E:\Technology\Magicodes.IE.Excel\Magicodes.IE.Excel\Program.cs:line 15

@xin-lai 请帮忙尽快解决,谢谢

【2.0】Excel导出重构

  • 重构整个Excel导出模块
  • 支持数据拆分成多个Sheet导出(不仅仅是DataTable)
  • 导出结果支持数据筛选(数据表)
  • 支持列筛选器,移除ColumnHeaderStringFunc
  • 优化忽略列

分页导出功能【需求】

前提:
导出数据量比较大且耗时的时候,前端会和后端失去交互或者前端会等不到后端接口的结果(超时),基于这种情况下,支持分页导出就是最好的选择,
思路:
1、首次导出的时候,导出数据及表头
2、再次导出的时候,读取首次(首次保存文件路径)文件流,在文件流的基础上再把本次的数据写入到新的文件流中
说明:
这样,前端会得到一个实时的进度,(思路来自于表格分页查询)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.