String path = "c: // date // xyu.txt "; StreamReader sr = new StreamReader (path ); String strLine = sr. ReadLine (); Int rowNum = 1; Object missing = System. Reflection. Missing. Value; ApplicationClass app = new ApplicationClass (); App. Application. Workbooks. Add (true ); Workbook book = (Workbook) app. ActiveWorkbook; Worksheet sheet = (Worksheet) book. ActiveSheet; Range r = sheet. get_Range ("A1", "C1 "); // Obtain the number of rows Object [,] objectData = new object [65535, 3]; While (! String. IsNullOrEmpty (strLine )) { String [] tempArr; TempArr = strLine. Split (','); For (int k = 1; k <= tempArr. Length; k ++) { ObjectData [rowNum-1, k-1] = tempArr [k-1]; } StrLine = sr. ReadLine (); RowNum ++; } R = r. get_Resize (65535, 3 ); R. Value2 = objectData; R. EntireColumn. AutoFit (); // Save the excel file Book. SaveCopyAs ("D: // source.xls "); // Close the file Book. Close (false, missing, missing ); // Exit excel App. Quit (); MessageBox. Show ("conversion successful! "); |