Coder Social home page Coder Social logo

Comments (5)

meld-cp avatar meld-cp commented on August 17, 2024

Hi @MartinGreen,

I tested with similar code and it seems to work with the latest commit. Does the code below work for you on v1.33.0?

[Fact]
public void Issue632_1()
{
    //https://github.com/mini-software/MiniExcel/issues/632
    var values = new List<Dictionary<string, object>>();

    foreach ( var item in Enumerable.Range( 1, 100 ) ) {
        var dict = new Dictionary<string, object>
        {
            { "Id", item },
            { "Time", DateTime.Now.ToLocalTime() },
            { "CPU Usage (%)", Math.Round( 56.345, 1 ) },
            { "Memory Usage (%)", Math.Round( 98.234, 1 ) },
            { "Disk Usage (%)", Math.Round( 32.456, 1 ) },
            { "CPU Temperature (°C)", Math.Round( 74.234, 1 ) },
            { "Voltage (V)", Math.Round( 6.3223, 1 ) },
            { "Network Usage (Kb/s)", Math.Round( 4503.23422, 1 ) },
            { "Instrument", "QT800050" }
        };
        values.Add( dict );
    }

    var config = new OpenXmlConfiguration
    {
        TableStyles = TableStyles.None,
        DynamicColumns = new DynamicExcelColumn[]
        {
            new DynamicExcelColumn("Time") { Index = 0, Width = 20, Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern },
        }
    };

    var path = Path.Combine(
        Path.GetTempPath(),
        string.Concat( nameof( MiniExcelIssueTests ), "_", nameof( Issue632_1 ), ".xlsx" )
    );
    
    MiniExcel.SaveAs( path, values, excelType: ExcelType.XLSX, configuration: config, overwriteFile: true );
    
}```

from miniexcel.

MartinGreen avatar MartinGreen commented on August 17, 2024

Hi @meld-cp

I tested your example and it does fail to produce a valid file for me. However, I was able to narrow it down further.

If I remove the Format value from the config it will create a valid file.

var config = new OpenXmlConfiguration
{
    TableStyles = TableStyles.None,
    DynamicColumns = new DynamicExcelColumn[]
    {
        new DynamicExcelColumn("Time") { Index = 0, Width = 20, /*Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern*/ },
    }
};

The moment I add Format it fails again, even with a simpler value than I was originally using. I also tried InvariantCulture with the same result.

I also tested this with 1.34 and its the same behaviour.

Thanks.

from miniexcel.

meld-cp avatar meld-cp commented on August 17, 2024

@MartinGreen interesting 🤔

Does changing the style to: TableStyles = TableStyles.Default, work by chance?

from miniexcel.

MartinGreen avatar MartinGreen commented on August 17, 2024

@meld-cp
Yeah changing the TableStyles fixes it!

from miniexcel.

meld-cp avatar meld-cp commented on August 17, 2024

Nice!... so the None style is broken/out of date... working on a fix 🤞

from miniexcel.

Related Issues (20)

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.