Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); workbook.Sheets.Add(); Microsoft.Office.Interop.Excel._Worksheet worksheet1 = null; worksheet1 = (Microsoft.Office.Interop.Excel._Worksheet)workbook.Sheets[1]; var itemset1 = webBrowser2.Document.GetElementById(idList[0]); string str1 = ""; int rowCount1 = itemset1.GetElementsByTagName("tr").Count; int colCount1 = itemset1.GetElementsByTagName("tr")[0].GetElementsByTagName("td").Count; for (int i = 0; i < rowCount1; i++) { for (var j = 0; j < colCount1; j++) { if (itemset1.GetElementsByTagName("tr")[i].GetElementsByTagName("td")[j].InnerText == "th") { str1 = itemset1.GetElementsByTagName("tr")[i].GetElementsByTagName("th")[j].InnerText; } else { str1 = itemset1.GetElementsByTagName("tr")[i].GetElementsByTagName("td")[j].InnerText; } worksheet1.Cells[i + 1, j + 1] = str1; } } string fileDestination = @"D:\test.xls"; if (File.Exists(fileDestination)) { File.Delete(fileDestination); } workbook.SaveAs(fileDestination, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing); workbook.Close(true, Type.Missing, Type.Missing); Process.Start(fileDestination); app.Quit();
worksheet1.get_Range("A1:C55").Merge(); //or worksheet1.get_Range(worksheet1.Cells[1,1],worksheet1.Cells[3,5]).Merge(); //or oRng = ws.get_Range("A1", "B2"); oRng.Merge(Missing.Value);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)