logo
down
shadow

Lumenworks Csv reader To read columns with same Names Or avoid ` An item with the same key has already been added`


Lumenworks Csv reader To read columns with same Names Or avoid ` An item with the same key has already been added`

By : Kushal Topnani
Date : November 18 2020, 03:49 PM
should help you out You've stumped me -- I don't know of any CSV parser that accounts for duplicate column headers, and I've tested quite a few of them. There are CSV parsers which will give you raw column data, though, and with some leg work you can use this as a building block to get your data into a friendlier state.
This will return a sequence of Dictionary>, one for each record, with the key being the header and the list being all the columns with the same header:
code :
using System.IO;
using System.Collections.Generic;
using Ctl.Data;

static IEnumerable<Dictionary<string, List<string>>> ReadCsv(string filePath)
{
    using (StreamReader sr = new StreamReader(filePath))
    {
        CsvReader csv = new CsvReader(sr);

        // first read in the header.

        if (!csv.Read())
        {
            yield break; // an empty file, break out early.
        }

        RowValue header = csv.CurrentRow;

        // now the records.

        while (csv.Read())
        {
            Dictionary<string, List<string>> dict =
                new Dictionary<string, List<string>>(header.Count);

            RowValue record = csv.CurrentRow;

            // map each column to a header value

            for (int i = 0; i < record.Count; ++i)
            {
                // if there are more values in the record than the header,
                // assume an empty string as header.

                string headerValue = (i < header.Count ? header[i].Value : null)
                    ?? string.Empty;

                // get the list, or create if it doesn't exist.

                List<string> list;

                if (!dict.TryGetValue(headerValue, out list))
                {
                    dict[headerValue] = list = new List<string>();
                }

                // finally add column value to the list.

                list.Add(record[i].Value);
            }

            yield return dict;
        }
    }
}


Share : facebook icon twitter icon
Spring Batch Item Reader - use skippedLinesCallback to set input field names

Spring Batch Item Reader - use skippedLinesCallback to set input field names


By : Karan
Date : March 29 2020, 07:55 AM
it fixes the issue You can:
declare your DelimitedLineTokenizer bean not anonymous (call it lineTokenizer) in skippedLinesCallback set lineTokenizer reference as property in your SkippedLineCallback: split header then set as names in lineTokenizer ref setted before
Can Lumenworks CSV parser error when there are too many columns in a row?

Can Lumenworks CSV parser error when there are too many columns in a row?


By : leroy
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Try using the DataTable csv reader (nuget csvtools) from Mike Stall.
If in any of the Read methods in DataTable.New you set allowMismatch = false, then it will throw an exception if the number of columns in a given row does not equal the expected number of columns.
reset enumerator to start for Lumenworks CSV Reader

reset enumerator to start for Lumenworks CSV Reader


By : Andrew Bailey
Date : March 29 2020, 07:55 AM
Hope this helps Did you try IEnumerator.Reset
code :
e.Reset();
var secondEnumerator = this.InternalCsv.GetEnumerator();
Getting screen reader to read new content added with JavaScript

Getting screen reader to read new content added with JavaScript


By : user3920243
Date : March 29 2020, 07:55 AM
this will help The WAI-ARIA specification defines several ways by which screen readers can "watch" a DOM element. The best supported method is the aria-live attribute. It has modes off, polite,assertive and rude. The higher the level of assertiveness, the more likely it is to interrupt what is currently being spoken by the screen reader.
The following has been tested with NVDA under Firefox 3 and Firefox 4.0b9:
LumenWorks Csv Reader - How do I detect columns that are present in the data rows but not in the columns?

LumenWorks Csv Reader - How do I detect columns that are present in the data rows but not in the columns?


By : Marley Mokomoko-Youn
Date : March 29 2020, 07:55 AM
I wish did fix the issue. It does this because it uses the first row to know how many columns your file has. If you change the first row to "heading1,heading2,heading3,," it will work as expected.
Related Posts Related Posts :
  • Why does C# also not allow empty conditions in while loops?
  • Unable to get a block of code into my regex match groups
  • What is difference between dbcontext.Add and dbcontext.AddObject
  • How do I update the file version number of C# DLL without recompiling?
  • Value for html control always null
  • HttpClient hangs when timeout is setting (Windows Phone)
  • Handle Multiple Form tag in asp.net page?
  • create word document with html content in c#
  • Confusion about Find And Replace
  • Format sms messages in Clickatell
  • Automated Function Overload
  • String to date in MS Access SQL statement gives type mismatch error
  • ShowDialog exiting on certain events
  • Is there a try Convert.ToInt32... avoiding exceptions
  • How to move wpf application into minimize tray at Window Start-up C#?
  • How to change display format of long variable?
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org