That won't work out too well because only parts of the array need to be fixed. Should I make another array just for dates??
My code is here
*******************
using System;
using Microsoft.Office.Interop.Excel;
using System.Threading;
using System.IO;
namespace ExcelExample
{
/// <summary>
///
/// </summary>
class ExcelClass
{
/// <summary>
///
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Data Extractor");
//Open Excel
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); // Creates a new Excel Application
excelApp.Visible = false; // Makes Excel not visible to the user.
string path = "c:/temp/pmCards/";
string[] workbooks = Directory.GetFiles(path, "*.xls");
//Create a CSV file to write to
TextWriter tw = new StreamWriter("c:/temp/pm1.csv");
//Create the header
string cellName = "Proj_Num,ProjNA,Exec_Spon,Proj_Own,Proj_Mgr,Proj_Desc,Org,Effect_DT,Pyxis_No,Depend,ITD_capbudg,ITD_capact,ITD_capvar,YTD_capbudg,YTD_capact,YTD_capvar,YEF_capbudg,YEF_capact,YEF_capvar,ITD_expbudg,ITD_expact,ITD_expvar,YTD_expbudg,YTD_expact,YTD_expvar,YEF_expbudg,YEF_expact,YEF_expvar";
//Write it
tw.WriteLine(cellName);
//For each workbook
foreach (string s in workbooks)
{
//TEMP
Console.WriteLine("FOUND");
// The following code opens an existing workbook
string workbookPath = s; // Add your own path here
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true,
false, 0, true, false, false);
// The following gets the Worksheets collection
Microsoft.Office.Interop.Excel.Sheets excelSheets = excelWorkbook.Worksheets;
// The following gets Scorecard Sheet for editing
string currentSheet = "Scorecard";
Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(currentSheet);
// The following gets a cell
string cell;
cell = "K53";
Microsoft.Office.Interop.Excel.Range excelCell = (Microsoft.Office.Interop.Excel.Range)excelWorksheet.get_Range(cell, cell);
//************ Extraction of Number from Filename Function ***********
FileInfo fileToRead = new FileInfo(workbookPath);
string fileNameWithOutSextension = fileToRead.FullName.Replace(fileToRead.Extension, "");
string numberInTheFileName = string.Join(null, System.Text.RegularExpressions.Regex.Split(fileNameWithOutSextension, "[^\\d]"));
int numberAsInteger = Int32.Parse(numberInTheFileName);
string projectID;
projectID = numberAsInteger.ToString();
//******** END Extraction of Number from Filename Function ***********
//Create cell array
string[] cellData = new string[] { "K53", "C3", "C5", "C7", "C6", "C9", "H6", "I3", "J6", "H9", "I17", "J17", "K17", "I20", "J20", "K20", "I23", "J23", "K23", "I18", "J18", "K18", "I21", "J21", "K21", "I24", "J24", "K24" };
for (int i = 0; i <= 27; i++)
{
cell = cellData;
excelCell = excelWorksheet.get_Range(cell, cell);
cellData = excelCell.Value2 + "";
//Take away commas in strings to have pure data for CSV
string commaClear = cellData;
commaClear = commaClear.Replace(",", "");
cellData = commaClear;
//Write Correct ProjNo to Array
cellData[0] = projectID;
Console.WriteLine(cellData);
}
//Converts the date to proper format
string serialDateS;
serialDateS = cellData[7];
int serialDate;
serialDate = Convert.ToInt32(cellData[7]);
int l = serialDate + 68569 + 2415019;
int n = (int)((4 * l) / 146097);
l = l - (int)((146097 * n + 3) / 4);
int k = (int)((4000 * (l + 1)) / 1461001);
l = l - (int)((1461 * k) / 4) + 31;
int j = (int)((80 * l) / 2447);
int month = l - (int)((2447 * j) / 80);
l = (int)(j / 11);
int day = j + 2 - (12 * l);
int year = 100 * (n - 49) + k + l;
string dateConverted = (day + "/" + month + "/" + year);
//END
//Convert date to correct format
cellData[7] = dateConverted;
Console.WriteLine("********* END Project *********");
//Takes the array and converts it to a comma spaced string
string cellDataStr = String.Join(",", cellData);
//Writes the string to a text file
tw.WriteLine(cellDataStr);
}
//Do not ask excel to save
excelApp.DisplayAlerts = false;
//Exit excel
excelApp.Quit();
//Close the file
tw.Close();
}
}
}
*******************