IWorkbook workbook; string fileExt = Path.GetExtension(fileName).ToLower(); using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { //XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式 if (fileExt == ".xlsx") { workbook = new XSSFWorkbook(fs); } else if (fileExt == ".xls") { workbook = new HSSFWorkbook(fs); } else { workbook = null; msg = "选择的文件格式不正确"; return null; } } ISheet sheet = workbook.GetSheetAt(0); IRow row = sheet.GetRow(0); var cell1 = row.GetCell(0); XSSFCellStyle rowsStyleColor = (XSSFCellStyle)workbook.CreateCellStyle(); XSSFColor xssfColor = new XSSFColor(); //根据本身须要设置RGB byte[] colorRgb = { (byte)255, (byte)255, (byte)0 }; xssfColor.SetRgb(colorRgb); rowsStyleColor.FillForegroundColorColor = xssfColor; rowsStyleColor.FillPattern = FillPattern.SolidForeground; cell1.CellStyle = rowsStyleColor; using (FileStream fileStream = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite)) { workbook.Write(fileStream); fileStream.Close(); }
弹出居中:
var newwin; if (newwin != undefined) { newwin.close(); } newwin = window.open( url, "onlywin", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, height=700,width=1370,left=280,top=300"); newwin.focus.document.open("text/html", "GB2312") newwin.focus.window.moveTo(parseInt((screen.availWidth - 1370) / 2), parseInt((screen.availHeight - 700) / 2)) //(当前屏幕高度减去弹窗高度)/2 (当前屏幕宽度-弹窗宽度)/2 newwin.focus();
浙公网安备 33010602011771号