public void OpenExcel2(string fileName) { //try //{ if (!CheckVersion(fileName)) { return; } IWorkbook workBook = _application.Workbooks.Open(fileName); IWorksheets sheets = workBook.Worksheets; int targetId = 286; //GetWorksheetPipeSilt(sheets[0], targetId);//雨水下水道淤積紀錄 //GetWorksheetPipeCross(sheets[1], targetId);//雨水下水道管線橫越紀錄 //GetWorksheetPipeOther(sheets[2], targetId);//雨水下水道管線破損及其他紀錄 //GetWorksheetPipeCableAttach(sheets[3], targetId);//雨水下水道纜線附掛紀錄 GetWorksheetPipeUnableWalk(sheets[4], targetId);//雨水下水道無法縱走紀錄 ReWorkingReport(targetId); //}catch(Exception ex) //{ //} }
/// <summary> /// Gets a range object from an existing instance or new one /// if source is null, then adds a new worksheet and return the used range /// if source is Range, then return the range /// if source is Worksheet, then return the used range /// if source is string, then parse the source and return the range /// </summary> /// <param name="source">Reference, range or worksheet</param> /// <returns>Range</returns> public static IRange GetRange(object source) { //Get a running instance of Excel or create one IExcel excel = ExcelExt.GetInstance(); //Handle null source IWorksheets worksheets = excel.Worksheets; if (source == null) { //Add a new sheet to the current workbook IWorksheet lastWorksheet = worksheets[worksheets.Count]; IWorksheet newWorksheet = worksheets.Add(Type.Missing, lastWorksheet, Type.Missing, Type.Missing); return(newWorksheet.UsedRange); } //Handle source as address if (source is string) { //try parse worksheet name var srctxt = source as string; if (srctxt != null && srctxt.IndexOf('!') == -1 && srctxt.IndexOf(':') == -1) { try { return(((IWorksheet)worksheets[source]).UsedRange); } catch { } } //try parse range name try { return(excel[source, Type.Missing]); } catch { throw new ExcelSourceError("Failed to resolve the source:\n{0}", source); } } //Handle source as Worksheet IWorksheet worksheet = source as IWorksheet; if (worksheet != null) { return(worksheet.UsedRange); } //Handle source as Range IRange range = source as IRange; if (range != null) { return(range); } throw new ExcelSourceError("Invalid type of source: {0}", source.GetType().Name); }
public void OpenExcel(string fileName) { //try //{ if (!CheckVersion(fileName)) { return; } IWorkbook workBook = _application.Workbooks.Open(fileName); IWorksheets sheets = workBook.Worksheets; int targetId = 285; //InsertGisMenu("T05", "10018", "新竹市", "新竹市漁港特定區"); //195; GetWorksheetRcp(sheets[0], targetId); //雨水竣工管線(102)- 804020102 GetWorksheetRcm(sheets[1], targetId); //雨水竣工人孔(202)- 804020202 GetWorksheetCp(sheets[2], targetId); //連接管(103)- 804020103 GetWorksheetSw(sheets[3], targetId); //集水井(204)- 804020204 GetWorksheetRd(sheets[4], targetId); //雨水側溝(601) - 804020601 //}catch(Exception ex) //{ //} }