Shane_Nicholson
Member
- Joined
- Nov 8, 2020
- Messages
- 8
- Programming Experience
- Beginner
Good morning all,
First of all, thank you for taking the time to read my post.
I have made a windows form, which works fine. The user will input the data and hit "insert", which saves the data as a CSV file. The data is then being importing into Tableau which needs the date format as yyyyMMdd. I cannot for the life of me figure out how to code C# to save the date as yyyyMMdd once saved as CSV. No matter what I do, it always saves it as MMddyyyy.
I have coded textBox11 to display todays date for the user. I simply need textBox11 date to save as yyyyMMdd when converted to a CSV file..
Below is the code I am using to export the file to CSV.
Thank you so much for taking the time to check this out.
First of all, thank you for taking the time to read my post.
I have made a windows form, which works fine. The user will input the data and hit "insert", which saves the data as a CSV file. The data is then being importing into Tableau which needs the date format as yyyyMMdd. I cannot for the life of me figure out how to code C# to save the date as yyyyMMdd once saved as CSV. No matter what I do, it always saves it as MMddyyyy.
I have coded textBox11 to display todays date for the user. I simply need textBox11 date to save as yyyyMMdd when converted to a CSV file..
Below is the code I am using to export the file to CSV.
Thank you so much for taking the time to check this out.
private void textBox11_TextChanged(object sender, EventArgs e)
{
textBox11.Text = DateTime.Now.ToString("yyyy-MM-dd");
Excel.Workbook xlworkbook;
Excel.Worksheet xlworksheet;
object misValue = System.Reflection.Missing.Value;
xlworkbook = xlap.Workbooks.Add(misValue);
xlworksheet = (Excel.Worksheet)xlworkbook.Worksheets.get_Item(1);
Excel.Sheets worksheets = xlworkbook.Worksheets;
worksheets[3].Delete();
worksheets[2].Delete();
xlworksheet.Cells[1, 1] = textBox1.Text;
xlworksheet.Cells[1, 2] = textBox11.Text = DateTime.Now.ToString("yyyy-MM-dd");
xlworksheet.Cells[1, 3] = textBox2.Text;
xlworksheet.Cells[1, 4] = textBox3.Text;
xlworksheet.Cells[1, 5] = textBox4.Text;
xlworksheet.Cells[1, 6] = textBox5.Text;
xlworksheet.Cells[1, 7] = textBox6.Text;
xlworksheet.Cells[1, 8] = textBox7.Text;
xlworksheet.Cells[1, 9] = textBox8.Text;
xlworksheet.Cells[1, 10] = textBox9.Text;
xlworksheet.Cells[1, 13] = textBox10.Text;
xlworksheet.Cells[1, 11] = comboBox1.Text;
xlworksheet.Cells[1, 12] = comboBox2.Text;
xlworkbook.SaveAs(@"\\172.21.4.14\BusinessLanding\BusinessLanding_Sync\operations_sync\FlightPlanning\savings_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv", Excel.XlFileFormat.xlCSVWindows);
xlworkbook.Close(true);
xlap.Quit();