xxxxxxxxxx
import pandas as pd
# Read CSV file
df = pd.read_csv('input.csv')
# Convert DataFrame to Excel file
df.to_excel('output.xlsx', index=False)
xxxxxxxxxx
import pandas as pd
data = pd.read_csv("k.csv")
data.to_excel("new_file.xlsx", index=None, header=True)
xxxxxxxxxx
import pandas as pd
# Read Excel file
excel_file = pd.read_excel('path/to/excel_file.xlsx')
# Convert to CSV
csv_file_path = 'path/to/output_file.csv'
excel_file.to_csv(csv_file_path, index=False)
print(f'Successfully converted Excel file to CSV: {csv_file_path}')
xxxxxxxxxx
#UI
File>> Save As>> Rename the file .csv>> Save
#Online
https://www.zamzar.com/convert/xls-to-csv/
xxxxxxxxxx
private IEnumerable<string[]> ReadCsv(string fileName, char delimiter = ';')
{
var lines = System.IO.File.ReadAllLines(fileName, Encoding.UTF8).Select(a => a.Split(delimiter));
return (lines);
}
xxxxxxxxxx
private IEnumerable<string[]> ReadCsv(string fileName, char delimiter = ';')
{
var lines = System.IO.File.ReadAllLines(fileName, Encoding.UTF8).Select(a => a.Split(delimiter));
return (lines);
}
xxxxxxxxxx
private IEnumerable<string[]> ReadCsv(string fileName, char delimiter = ';')
{
var lines = System.IO.File.ReadAllLines(fileName, Encoding.UTF8).Select(a => a.Split(delimiter));
return (lines);
}
xxxxxxxxxx
private static bool ConvertWithNPOI(string excelFileName, string worksheetName, IEnumerable<string[]> csvLines)
{
if (csvLines == null || csvLines.Count() == 0)
{
return (false);
}
int rowCount = 0;
int colCount = 0;
IWorkbook workbook = new XSSFWorkbook();
ISheet worksheet = workbook.CreateSheet(worksheetName);
foreach (var line in csvLines)
{
IRow row = worksheet.CreateRow(rowCount);
colCount = 0;
foreach (var col in line)
{
row.CreateCell(colCount).SetCellValue(TypeConverter.TryConvert(col));
colCount++;
}
rowCount++;
}
using (FileStream fileWriter = File.Create(excelFileName))
{
workbook.Write(fileWriter);
fileWriter.Close();
}
worksheet = null;
workbook = null;
return (true);
}
xxxxxxxxxx
with open('dict.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
for key, value in mydict.items():
writer.writerow([key, value])
xxxxxxxxxx
// a c# method to convert excel files to csv using excel introp
using System;
using System.Text;
using Microsoft.Office.Interop.Excel;
static void ExcelToCsv(string sourceFilePath, string targetFilePath)
{
Application application = null;
Workbook wb = null;
Worksheet ws = null;
try
{
application = new Application();
application.DisplayAlerts = false;
wb = application.Workbooks.Open(sourceFilePath);
ws = (Worksheet)wb.Sheets[1];
ws.SaveAs(targetFilePath, XlFileFormat.xlCSV);
}
catch (Exception e)
{
// Handle exception
}
finally
{
if (application != null) application.Quit();
if (ws != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
if (wb != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
if (application != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(application);
}
}