You need to sign in to do that
Don't have an account?
edukondalu thodeti
how to get first row header names of the CSV files
Hi
how to get the first row header names of the csv files when we are uploading the file using lightning component
i need to that header names in the box of next page when i click on the next page lightning button
Pls help me
how to get the first row header names of the csv files when we are uploading the file using lightning component
i need to that header names in the box of next page when i click on the next page lightning button
Pls help me
Like this -
this.fileReader= new FileReader();
console.log(this.fileReader);
this.fileReader.onloadend = (() => {
this.fileContents = this.fileReader.result;
console.log(this.fileContents);
Then in apex, using the below logic you will get the CSV headers -
String stringFile = EncodingUtil.urlDecode(fileContents, 'UTF-8');
String fileLines = stringFile.split('\n')[0];
List<String> csvHeaders = new List<String>();
for(String strline : fileLines.split(',')){
csvHeaders.add(strline.trim());
}
"fileContents" is a String variable that you will pass from JS to the apex.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.