Good afternoon, I would like to know how to import a library into C#, I need a library to export or convert a csv file to xlsx.
Would you help me?
Good afternoon, I can import the dll library and export the hitorian table in .csv and convert it to xlsx.
How do I change the name of a column in the historian table only at export time?
Hello Thaylor
You can use the code bellow to change the name of a column in a csv file.
public void RenameColumn(string filePath, string oldColumnName, string newColumnName)
{
// Read the entire CSV file into a string array
string[] lines = File.ReadAllLines(filePath);
if (lines.Length == 0)
{
Console.WriteLine("The CSV file is empty.");
return;
}
// Split the header line
string[] headers = lines[0].Split(',');
// Find the column index with the old name
int columnIndex = Array.IndexOf(headers, oldColumnName);
if (columnIndex == -1)
{
@Info.Trace("The column '" + oldColumnName + "' was not found.");
return;
}
// Replace the old column name with the new column name
headers[columnIndex] = newColumnName;
// Join the headers back into a string
lines[0] = string.Join(",", headers);
// Write the updated lines back to the CSV file
File.WriteAllLines(filePath, lines);
@Info.Trace("The column '" + oldColumnName + "' has been renamed to '" + newColumnName + "'.");
}
Best Regards
Vitor Cammarosano
Tatsoft Team