Code Monkey home page Code Monkey logo

traf72 / excel-report-generator Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 6.0 6.92 MB

ExcelReportGenerator is a .NET library which allows you to render data to Microsoft Excel by marking Excel sheets using panels and templates. It makes it easy to connect to various data sources and to render data from them to Excel. You can also apply aggregation, various types of grouping, formatting and so on.

License: MIT License

C# 100.00%
closedxml excel generator report reporting reports spreadsheet workbook worksheet xlsx

excel-report-generator's People

Contributors

traf72 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

Watchers

 avatar  avatar  avatar

excel-report-generator's Issues

How does this work with nested tables?

How does this work with nested tables? I have a complex object which I want to export to excel as nested tables. Example POCO classes are shown as below:

class Company
{
public string CompanyName { get; set; }
public Address CompanyAddress { get; set; }
public decimal YearSales { get; set; }
public decimal YearProfit { get; set; }
public List Investers { get; set; }
public List Employees { get; set; }
}

class Investor
{
public string InvestorName { get; set; }
public DateTime InvestmentDate { get; set; }
public decimal Percentage { get; set; }
}

class Employee
{
public string EmployeeName { get; set; }
public DateTime HiringDate { get; set; }
public decimal Salary { get; set; }
}

class Address
{
public int StreetNumber { get; set; }
public string StreetName { get; set; }
public string OfficeNumber { get; set; }
public string CountryName { get; set; }
public string StateName { get; set; }
public string PostalCode { get; set; }
public List Telephone { get; set; }
}

class PhoneNumber
{
public int CountryCode { get; set; }
public int AreaCode { get; set; }
public string PhoneNumber { get; set; }
public int Extension { get; set; }
}

All the data is in a single c# object. I am wondering how the ExcelReportGenerator can help achieve my goal?

How can I set predicate for column?

I want to filter data items by predicate. I tried set native excel filter on columns, but i need date filter for date values etc. Because column template configuration follows after column name, excel offers text filter.

How can i configure ExcelReportGenerator for filtering output data by predicate?

RichText cells

Hello. I faced with a problem when filling out cells with rich formatting.
So, for example, after rendering, template cell with "some {p:MyValue} text" turns into "some simple text", losing formatting.
Is it possible to add processing for such cells?
It seems to me that can be done (of course with correct formatting) by changing the code in ExcelPanel.cs something like...

  1. instead of lines [103...141] insert:
    if (!cell.HasRichText)
    {
        MatchCollection matches = Regex.Matches(cellValue, templatePattern, RegexOptions.IgnoreCase);
        if (matches.Count == 0)
        {
            continue;
        }
        XLCellValue newValue = GetCellValue(cellValue, templatePattern, matches);
        cell.Value = newValue;
    }
    else
    {
        IXLRichText richText = cell.GetRichText();
        foreach(IXLRichString richString in richText)
        {
            string cellPartValue = richString.Text;
            MatchCollection matches = Regex.Matches(cellPartValue, templatePattern, RegexOptions.IgnoreCase);
            if (matches.Count == 0)
            {
                continue;
            }
            XLCellValue newValue = GetCellValue(cellPartValue, templatePattern, matches);
            richString.Text = newValue.GetText();
        }
    }
  1. and removed code put in separate function:
private XLCellValue GetCellValue(string cellValue, string templatePattern, MatchCollection matches)
    {
        HierarchicalDataItem dataContext = GetDataContext();
        if (matches.Count == 1 && Regex.IsMatch(cellValue, $@"^{templatePattern}$", RegexOptions.IgnoreCase))
        {
            object value = _templateProcessor.GetValue(cellValue, dataContext);
            if (value == null)
            {
                return Blank.Value;
            }
            else if (value.GetType().IsNumeric())
            {
                return Convert.ToDouble(value);
            }
            else
            {
                return value switch
                {
                    bool boolValue => boolValue,
                    DateTime dateTimeValue => dateTimeValue,
                    TimeSpan timeSpanValue => timeSpanValue,
                    _ => GetValueFromString(value.ToString())
                };
            }
        }

        foreach (object match in matches)
        {
            string template = match.ToString();
            cellValue = cellValue.Replace(template, _templateProcessor.GetValue(template, dataContext)?.ToString());
        }
        return GetValueFromString(cellValue);

        XLCellValue GetValueFromString(string value) => value == string.Empty ? Blank.Value : value;
    }

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.