void rename(string initPath) { string folderName = Path.GetFileName(initPath); string[] listInitFile = Directory.GetFiles(initPath, "*" + _oldModuleCode + "*", SearchOption.TopDirectoryOnly); foreach (string filePath in listInitFile) { string fileName = Path.GetFileName(filePath); if (folderName.StartsWith("DOC.") && Path.GetExtension(filePath) == ".xlsm") { Excel.Application objXLApp = default(Excel.Application); Excel.Workbook objXLWb = default(Excel.Workbook); Excel.Worksheet objXLWs = default(Excel.Worksheet); try { objXLApp = new Excel.Application(); objXLApp.Workbooks.Open(filePath); objXLWb = objXLApp.Workbooks[1]; objXLWs = (Excel.Worksheet)objXLWb.Worksheets[1]; if (fileName.StartsWith("DMVTC.")) { objXLWs.Cells[3, 3] = _newModuleName; objXLWs.Cells[3, 10] = "Mã: " + _newModuleCode; //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper(); objXLWs.PageSetup.LeftHeader = _newModuleName; } if (fileName.StartsWith("DTSB.")) { objXLWs.Cells[3, 3] = _newModuleName; objXLWs.Cells[3, 11] = _newModuleCode; //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper(); objXLWs.PageSetup.LeftHeader = _newModuleName; } if (fileName.StartsWith("HS.")) { objXLWs.Cells[5, 3] = _newModuleName; objXLWs.Cells[6, 3] = _newModuleCode; //objXLWs.Cells[7, 3] = Global.AppUserName.ToUpper(); objXLWs.PageSetup.LeftHeader = _newModuleCode + " - " + _newModuleName; } if (fileName.StartsWith("KCS.")) { objXLWs.Cells[3, 3] = _newModuleName; objXLWs.Cells[3, 7] = _newModuleCode; //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper(); objXLWs.PageSetup.LeftHeader = _newModuleName; } if (fileName.StartsWith("KTVC.")) { objXLWs.Cells[4, 3] = _newModuleName; objXLWs.Cells[4, 8] = _newModuleCode; //objXLWs.Cells[5, 3] = Global.AppUserName.ToUpper(); objXLWs.PageSetup.LeftHeader = _newModuleName; } if (fileName.StartsWith("XNVT.")) { objXLWs.Cells[3, 3] = _newModuleName; objXLWs.Cells[3, 10] = "Mã: " + _newModuleCode; //objXLWs.Cells[4, 3] = Global.AppUserName.ToUpper(); objXLWs.PageSetup.LeftHeader = _newModuleName; } } catch (Exception) { } finally { objXLApp.ActiveWorkbook.Save(); objXLApp.Workbooks.Close(); objXLApp.Quit(); } } if (Path.GetExtension(filePath) == ".xlsm") { TextUtils.ExcelFindAndReplace(filePath, _oldModuleCode, _newModuleCode); } TextUtils.RenameFileVB(filePath, Path.GetFileName(filePath).Replace(_oldModuleCode, _newModuleCode)); } string[] listInitFolder = Directory.GetDirectories(initPath, "*" + _oldModuleCode + "*", SearchOption.TopDirectoryOnly); foreach (string folderPath in listInitFolder) { rename(folderPath); } TextUtils.RenameFolderVB(initPath, Path.GetFileName(initPath).Replace(_oldModuleCode, _newModuleCode)); }