Folks! I am writing a program that takes data from a website via selenium web driver. I am trying to create football fixture for our projects. So far, I accomplished to take date and time, team names and scores from the website. One or two days ago, I asked Is there any way to write data to excel file. I tried epplus, but it is not easy to use, so I started to use Interop and I have a couple of questions.
Firstly, I need to check my file exist or not. Also, I need to access the current worksheet. Then, I need to check whether the first rows items exists or not. If it does not exist, I need to insert a new row to the index 1. I am not sure that I am doing right:
using Excel = Microsoft.Office.Interop.Excel; //namespace
var filePath = new FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
"\\Test" + "\\" + pathName + "\\" + subFile + "\\" + pathName + ".xlsx");
Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true;
object misValue = System.Reflection.Missing.Value;
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Test" + "\\" + pathName + "\\" + subFile + "\\" + pathName + ".xlsx";
if (filePath.Exists)
{
Excel.Workbook wb = xlApp.Workbooks.Open(path,0, false, misValue, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets.Item["Sheet1"];
for (int i = 0; i < dateTime.Count; i++)
{
if (string.Compare(ws.Cells[i + 1, 1], dateTime[dateTime.Count - i -1]) != 0 && string.Compare(ws.Cells[i + 1, 2], firstTeam[dateTime.Count - i - 1]) != 0 && string.Compare(ws.Cells[i + 1, 3], secondTeam[dateTime.Count - i - 1]) != 0)
{
ws.Cells.Rows.Insert(0);
ws.Cells[1, 1] = dateTime[dateTime.Count - i - 1];
ws.Cells[1, 2] = firstTeam[dateTime.Count - i - 1];
ws.Cells[1, 3] = secondTeam[dateTime.Count - i - 1];
}
}
}
I am trying to check data on the row, but i could not accomplished. My if condition not working I get this error: best overloaded method match for 'string.Compare(string, string)' has some invalid arguments' How can I do it? Also, Is my code right ?