I can export to this excel over two different text files on this code.
The code writes data to two different cells.
But what I want is to split a text file.
as below example:
Over a text file
example1 10
example1 20
example1 30
What I want the program to do
transfer to excel in this way
What I want is to split the list and transfer it to two different values
string[] InputNamesLine = File.ReadAllLines(@"C:/test/test.txt");
string[] InputLinksLine = File.ReadAllLines(@"C:/test/test1.txt");
excel.Application oXL;
excel._Workbook oWB;
excel._Worksheet oSheet;
excel.Range oRng;
object misvalue = System.Reflection.Missing.Value;
try
{
//start excel and get application object
oXL = new excel.Application();
oXL.Visible = true;
//Create new workbook
oWB = (excel._Workbook)(oXL.Workbooks.Add(""));
oSheet = (excel._Worksheet)oWB.ActiveSheet;
//Add table headers going cell
oSheet.Cells[1, 1] = "Parameter_Names";
oSheet.Cells[1, 2] = "Values";
//Format A1:B1 as bold and vertical alignment=center
oSheet.get_Range("A1", "B1").Font.Bold = true;
oSheet.get_Range("A1", "B1").VerticalAlignment = excel.XlVAlign.xlVAlignCenter;
for (int i = 1; i < InputNamesLine.Length; i = i + 2)
{
//oSheet.Cells[1][i + 1] = i;
oSheet.Cells[1][i + 2] = InputNamesLine[i];
oSheet.Cells[2][i + 2] = InputLinksLine[i];
}
for (int a = 0; a <= InputNamesLine.Length; a = a+2)
{
//oSheet.Cells[1][i + 1] = i;
oSheet.Cells[1][a+2] = InputNamesLine[a];
oSheet.Cells[2][a+2] = InputLinksLine[a];
}
//for (int a = 1; a <= InputNamesLine.Length; a = a + 2)
//{
// //oSheet.Cells[1][i + 1] = i;
// oSheet.Cells[1][a + 2] = InputNamesLine[a];
// oSheet.Cells[2][a + 2] = InputLinksLine[a];
//}
Thread.Sleep(5000);
oRng = oSheet.get_Range("A1", "B1");
//oRng.EntireColumn.AutoFit();
oWB.SaveAs(@"C:\test\texts1.xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
oWB.Close();
oXL.Quit();
}