//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); object[,] data = new object[,]{ {"Name", "City", "Birthday", "Eye color", "Weight", "Height"}, {"Richard", "New York", new DateTime(1968, 6, 8), "Blue", "67", "165"}, {"Damon", "Washington", new DateTime(1986, 2, 2), "Hazel", "76", "176"}, {"Angela", "Washington", new DateTime(1993, 2, 15), "Brown", "68", "145"} }; // Following code does not ignore the error of the first range. IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A:F"].ColumnWidth = 15; worksheet.Range["A1:F1"].Merge(); worksheet.Range["A1:F1"].Value = "Range errors not ignored"; worksheet.Range["A1:F1"].Font.Bold = true; worksheet.Range["A1:F1"].HorizontalAlignment = HorizontalAlignment.Center; worksheet.Range["A2:F5"].Value = data; worksheet.Tables.Add(worksheet.Range["A2:F5"], true); // Following code ignores the error of the second range. worksheet.Range["A7:F7"].Merge(); worksheet.Range["A7:F7"].Value = "Range errors ignored"; worksheet.Range["A7:F7"].Font.Bold = true; worksheet.Range["A7:F7"].HorizontalAlignment = HorizontalAlignment.Center; worksheet.Range["A8:F11"].Value = data; worksheet.Tables.Add(worksheet.Range["A8:F11"], true); worksheet.Range["A8:F11"].IgnoredError = IgnoredErrorType.All; // Save to an excel file workbook.Save("IgnoreRangeError.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim data(,) As Object = { {"Name", "City", "Birthday", "Eye color", "Weight", "Height"}, {"Richard", "New York", New DateTime(1968, 6, 8), "Blue", "67", "165"}, {"Damon", "Washington", New DateTime(1986, 2, 2), "Hazel", "76", "176"}, {"Angela", "Washington", New DateTime(1993, 2, 15), "Brown", "68", "145"} } ' Following code does not ignore the error of the first range. Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A:F").ColumnWidth = 15 worksheet.Range("A1:F1").Merge() worksheet.Range("A1:F1").Value = "Range errors not ignored" worksheet.Range("A1:F1").Font.Bold = True worksheet.Range("A1:F1").HorizontalAlignment = HorizontalAlignment.Center worksheet.Range("A2:F5").Value = data worksheet.Tables.Add(worksheet.Range("A2:F5"), True) ' Following code ignores the error of the second range. worksheet.Range("A7:F7").Merge() worksheet.Range("A7:F7").Value = "Range errors ignored" worksheet.Range("A7:F7").Font.Bold = True worksheet.Range("A7:F7").HorizontalAlignment = HorizontalAlignment.Center worksheet.Range("A8:F11").Value = data worksheet.Tables.Add(worksheet.Range("A8:F11"), True) worksheet.Range("A8:F11").IgnoredError = IgnoredErrorType.All ' save to an excel file workbook.Save("IgnoreRangeError.xlsx")