C# worksheet设置Excel样式
1.例子导出Excel的样式
样式代码
public void Exportdatagridviewtoexcel(string Textname)
{ SaveFileDialog savedialog = new SaveFileDialog();
savedialog.DefaultExt = "xlsx";
savedialog.Filter = "microsoft office execl files (*.xlsx)|*.xlsx";
savedialog.FilterIndex = ;
savedialog.RestoreDirectory = true;
savedialog.Title = "导出数据到excel表格";
savedialog.ShowDialog();
if (savedialog.FileName.IndexOf(":") < ) return; //被点了取消
//Microsoft.office.interop.excel.application xlapp = new microsoft.office.interop.excel.application();
Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
if (xlapp == null)
{
MessageBox.Show("可能您的机子未安装excel,无法创建excel对象!", "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
} Microsoft.Office.Interop.Excel.Workbooks workbooks = xlapp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[];//取得sheet1 string ADD = "盘点录入明细表 时间:" + DateTime.Now.ToShortDateString(); worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 7]).Font.Bold = true;//
worksheet.Cells[, ] = " " + Textname;
worksheet.Cells[, ] = "" + "使用科室";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
//worksheet.Cells[2, 5] = "" + "年月日";
worksheet.Cells[, ] = "患者姓名";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "性别";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "年龄";
worksheet.Cells[, ] = "住院号";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "床位号";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "手术名称";
worksheet.Cells[, ] = "使用部位";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "手术日期";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "医保类型"; worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "生产厂家";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = "注册证号";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = "生产日期";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "灭菌日期";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "有效日期";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "供货单位";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = "供货商签字";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "联系电话";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "产品名称";
worksheet.Cells[, ] = "规格型号";
worksheet.Cells[, ] = "产品批号";
worksheet.Cells[, ] = "单价";
worksheet.Cells[, ] = "数量";
worksheet.Cells[, ] = "单位";
worksheet.Cells[, ] = "金额 "; worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " "; worksheet.Cells[, ] = "高值耗材使用医生签字";
worksheet.Cells[, ] = "手术护士";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = "收费人员(记账人员)签字";
worksheet.Cells[, ] = "收费价格";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.Cells[, ] = "科室负责人签字";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = " ";
worksheet.Cells[, ] = "设备采购签字";
worksheet.Cells[, ] = " ";
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2, 10]).Text = ADD;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true; //worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2, 8]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
//worksheet.get_Range(worksheet.Cells[3, 1], worksheet.Cells[3, 8]).Font.Bold = true;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2, 8]).Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft].Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2, 8]).Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight].Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2, 8]).Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeTop].Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;
//worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[2, 8]).Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom].Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThick;
worksheet.Cells[, ] = "高值耗材唯一性标示";
//worksheet.get_Range(worksheet.Cells[17, 1], worksheet.Cells[17, 1]).VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).MergeCells = true;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).WrapText = true;//
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).Borders.Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlThin;
worksheet.get_Range(worksheet.Cells[, ], worksheet.Cells[, ]).HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; if (savedialog.FileName != "")
{
try
{
workbook.Saved = true;
workbook.SaveCopyAs(savedialog.FileName);
}
catch (Exception ex)
{
MessageBox.Show("导出文件时出错,文件可能正被打开!..." + ex.Message, "系统提示 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
//GC.Collect();//强行销毁
MessageBox.Show("数据导出成功! ", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); }
2.单元格样式设置
Excel.Range r =mySheet.get_Range(mySheet.Cells[,],mySheet.Cells[DT.Rows.Count + ,DT.Columns.Count - ]); r.NumberFormat="@"; //设置单元格格式为文本类型,文本类型可设置上下标 r.NumberForma="0.00_ "//设置单元格格式为数值类型,小数点后2位 r.NumberForma="¥#,##0.00;¥-#,##0.00"//设设置单元格格式为货币类型,小数点后2位 r.NumberForma=_"_ ¥*#,##0.00_;_ ¥*-#,##0.00_ ;_ ¥*""-""??_;_ @_ "//置单元格格式为会计专用类型,小数点后2位 r.NumberForma="yyyy-m-d"//设置单元格格式为日期类型 r.NumberForma="[$-F400]h:mm:ss AM/PM"//设置单元格格式为时间类型 r.NumberForma="0.00%"//设置单元格格式为百分比类型,小数点后2位 r.NumberForma="# ?/?"设置单元格格式为分数类型,分母为一位数 r.NumberForma="0.00E+00"//设置单元格格式为科学技术类型,小数位数为2 r.NumberForma=""//设置单元格格式为特殊类型 B、上下标格式的控制; mySheet.get_Range(mySheet.Cells[i+, DT.Columns.Count - ],mySheet.Cells[i + , DT.Columns.Count -]).get_Characters(a.Length+ ,b.Length).Font.Subscript =true;//控制输出样式为下标 mySheet.get_Range(mySheet.Cells[i+, DT.Columns.Count - ],mySheet.Cells[i + , DT.Columns.Count-]).get_Characters(a.Length + b.Length+ , c.Length).Font.Superscript =true; //控制输出样式为上标 C、单元格水平垂直对齐方式; //单元格水平,垂直居中 r.HorizontalAlignment=Excel.XlHAlign.xlHAlignCenter; r.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter; 上面代码中,枚举XLHAlign的值还有: // 右对齐 xlHAlignRight, // 左对齐. xlHAlignLeft, // 两端对齐. xlHAlignJustify, // 分散对齐(缩进) xlHAlignDistributed, // 居中对齐 xlHAlignCenter, // 依照数据类型对齐,常规 xlHAlignGeneral, // 填充 xlHAlignFill, // 跨列对齐. xlHAlignCenterAcrossSelection=, 枚举XLVAlign的值还有: // 靠上对齐 xlVAlignTop, //两端对齐. xlVAlignJustify=-, //分散对齐. xlVAlignDistributed, //居中对齐. xlVAlignCenter, //靠下对齐. xlVAlignBottom=-, D、 单元格边框设置; //设置边框 Excel.Range r =mySheet.get_Range(mySheet.Cells[,],mySheet.Cells[DT.Rows.Count + ,DT.Columns.Count - ]); r.Borders.LineStyle=Excel.XlLineStyle.xlContinuous; 枚举XlLineStyle中还有下面线形: //没边框线 xlLineStyleNone, //双线. xlDouble, //点状线. xlDot, //虚线. xlDash, //连续线. xlContinuous, //点线交互型 xlDashDot, //两点一线型 xlDashDotDot, //斜线. xlSlantDashDot, E、单元格合并 用get_Range方法获取要合并的单元格,再设置MergeCells属性的值进行合并。 代码: //合并单元格 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).MergeCells =true; F、字体设置 先用get_Range方法选中要设置字体的某个单元格或者或者直接用get_Characters方法直接选中要设置的字符进行设置; 代码: //加粗字体 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Font.Bold =true; //设置字体大小 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Font.Size=; //设置字体的颜色 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Font.ColorIndex = ; //设置字体 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Font.Name ="隶书"; //设置成斜体 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Font.Italic =true; //设置下划线 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Font.Underline =true; G、冻结行列 用get_Range方法获取单元格,再设置其Freezepanes属性为true,就把该单元格右上方的行和列都冻结了,取消冻结将其值设为false即可。 //冻结行列 myExcel.get_Range(myExcel.Cells[,],myExcel.Cells[,]).Activate(); myExcel.ActiveWindow.FreezePanes=true; H、 公式输入栏的隐藏 //设置是否显示Excel公式输入栏,默认为true myExcel.DisplayFormulaBar=false; I、 列标题与行标题的隐藏 //设置是否显示行和列的标题,默认为true myExcel.ActiveWindow.DisplayHeadings=false; J、网格的隐藏 //设置是否显示网格,默认为true myExcel.ActiveWindow.DisplayGridlines=false; K、 水平、垂直滚动条的隐藏 //设置是否显示水平滚动条 myExcel.ActiveWindow.DisplayHorizontalScrollBar=false; //设置是否显示垂直滚动条 myExcel.ActiveWindow.DisplayVerticalScrollBar=false; L、页的隐藏Sheet //设置是否显示Sheet页 myExcel.ActiveWindow.DisplayWorkbookTabs=false; M、 电子表格外观控制: Sheet.DisplayToolbar= false;//是否显示工具栏默认值为 true Sheet.DisplayOfficeLogo= false;// 取消显示Office图标 Sheet.DisplayColumnHeadings= false;// 是否显示列标题,默认是true Sheet.DisplayRowHeadings= false;// 是否显示行标题,默认是true Sheet.DisplayHorizontalScrollBar= false;// 是否显示水平滚动条,默认为true Sheet.DisplayVerticalScrollBar= false;// 是否显示垂直滚动条,默认为true Sheet.DisplayGridlines= false;// 电子表格是否显示网格,默认为true for (int i = ; i < DT.Columns.Count- ; i += ) { Sheet.get_Range(Sheet.Rows.Cells[i,],Sheet.Rows.Cells[i, DT.Columns.Count - ]).Interior.set_ColorIndex(); //设置行的颜色 } worksheet.Cells[, ]= "Excel单元格赋值";//Excel单元格赋值
range.Font.Size = ; //设置字体大小
range.Font.Underline=true; //设置字体是否有下划线
range.Font.Name="黑体";设置字体的种类
range.HorizontalAlignment=XlHAlign.xlHAlignCenter; //设置字体在单元格内的对其方式
range.ColumnWidth=; //设置单元格的宽度
range.Cells.Interior.Color=System.Drawing.Color.FromArgb(,,).ToArgb();//设置单元格的背景色
range.Borders.LineStyle=; //设置单元格边框的粗细
range.BorderAround(XlLineStyle.xlContinuous,XlBorderWeight.xlThick,XlColorIndex.xlColorIndexAutomatic,System.Drawing.Color.Black.ToArgb());//给单元格加边框
range.Borders.get_Item(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeTop).LineStyle=Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone;//设置单元格上边框为无边框
range.EntireColumn.AutoFit(); //自动调整列宽
Range.HorizontalAlignment= xlCenter; // 文本水平居中方式
Range.VerticalAlignment= xlCenter //文本垂直居中方式
Range.WrapText=true; //文本自动换行
Range.Interior.ColorIndex=; //填充颜色为淡紫色
Range.Font.Color=clBlue; //字体颜色
xlsApp.DisplayAlerts=false; //保存Excel的时候,不弹出是否保存的窗口直接进行保存 向Excel中填充数据,并保存为临时文件 Excel.ApplicationmyExcel =newExcel.Application(); //打开模板文件 myExcel.Application.Workbooks.Open(mode.FullName,missing,missing,missing, missing, missing, missing, missing, missing,missing, missing,missing,missing, missing, missing); //选中有数据的Cells Excel.WorkbookmyBook = myExcel.Workbooks[]; Excel.WorksheetmySheet = (Excel.Worksheet)myBook.Worksheets[]; Excel.Ranger = mySheet.get_Range(mySheet.Cells[,],mySheet.Cells[DT.Rows.Count + ,DT.Columns.Count - ]); r.Select(); //不单独显示Excel,最后在IE中显示 myExcel.Visible=false; //第一行为报表的标题 myExcel.Cells[,]= "用模板导出的报表"; //逐行写入数据,数组中第一行为报表的列标题 for (int i = ; i <DT.Columns.Count - ; i++) { myExcel.Cells[,+ i] =DT.Columns[i].Caption; ; } //在当前目录下指定一个临时文件 string FileName =Server.MapPath("~")+"""Temp.xls"; if (File.Exists(FileName)) { File.Delete(FileName); } myExcel.Save(FileName); mySheet.Cells.Clear(); //设置不出现保存提示框 myBook.Saved=true; myExcel.Application.Workbooks.Close();
框架4.0之上的导出 引用 Aspose.cell
public void importExcel(DataTable dt, string fileName, string filePath)
{
int posStart = ;//报表内容起始
//设置字体样式
Style style1 = new Style();
style1.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style1.VerticalAlignment = TextAlignmentType.Left;
style1.Font.Name = "宋体";
style1.Font.IsBold = true;//设置粗体
style1.Font.Size = ;//设置字体大小 Style style2 = new Style();
style2.HorizontalAlignment = TextAlignmentType.Center;
style2.Font.Size = ; Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[];
Cells cell = ws.Cells; int colCount = dt.Columns.Count;
int rowCount = dt.Rows.Count;
//合并第一行单元格,显示标题
Range range = cell.CreateRange(, , , colCount);
range.Merge();
cell["A1"].PutValue(fileName); //标题
cell.SetRowHeight(, );//设置行高
//给单元格关联样式
cell["A1"].SetStyle(style1); //报表名字 样式
//设置Execl列名
for (int i = ; i < colCount; i++)
{
cell[, i].PutValue(dt.Columns[i].ColumnName);
//cell[1, i].SetStyle(style2);
}
//设置单元格内容
for (int i = ; i < rowCount; i++)
{
for (int j = ; j < colCount; j++)
{
cell[i + posStart, j].PutValue((dt.Rows[i][j] + "").Trim());
//cell[i + posStart, j].SetStyle(style2);
}
}
//设置列宽
//for (int i = 1; i < dt.Columns.Count; i++)
//{
// cell.SetColumnWidthPixel(i - 1, int.Parse(dataGridView1.Columns[i].Width.ToString()));
//}
//保存excel表格
wb.Save(filePath); }
C# worksheet设置Excel样式的更多相关文章
- C# worksheet设置Excel样式(转载)
1.例子导出Excel的样式public void Exportdatagridviewtoexcel(string Textname) { SaveFileDialog savedialog = n ...
- POI 设置Excel样式(转)
POI 设置Excel样式 POI中可能会用到一些需要设置EXCEL单元格格式的操作小结: 先获取工作薄对象: HSSFWorkbook wb = new HSSFWorkbook(); HSSFSh ...
- asp.net将页面内容按需导入Excel,并设置excel样式,下载文件(解决打开格式与扩展名指定的格式不统一的问题)
//请求一个excel类 Microsoft.Office.Interop.Excel.ApplicationClass excel = null; //创建 Workbook对象 Microsoft ...
- Python设置Excel样式
前面已经详细讲解过使用Python对Excel表格进行读.写操作,本文主要讲解下使用Python设置Excel表格的样式. 深入学习请参考openpyxl官方文档: https://openpyxl. ...
- 20201203-6 设置excel样式【】
1-1 1 import os 2 from openpyxl import load_workbook 3 from openpyxl.styles import PatternFill, Alig ...
- asp.net数据导出到excel表格,并设置表格样式
1.首先在项目中添加引用
- Response输出excel设置文本样式
在网上查了些Response导出excel然后设置样式的方法,发现没有一个可行的于是开始自己研究, 发现可以通过输出样式的方式进行配置,我要设置的是全文本格式在excel样式是这样的mso-numbe ...
- POI HSSFCellStyle 设置 Excel 单元格样式
POI中可能会用到一些需要设置EXCEL单元格格式的操作小结: 先获取工作薄对象: HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb ...
- C# 设置Excel打印选项及打印excel文档
C# 设置Excel打印选项及打印excel文档 打印Excel文档是一个很常见的操作,但有时候我们会碰到各种不同的打印需求,例如只打印一个Excel工作表的其中一部分,或打印时每页都有表头,或把工作 ...
随机推荐
- shell中的输入输出和编程中的变量(shell 03)
shell中的输入输出标准输入:键盘标准输出:终端显示器>> 追加是换行追加的echo -n 不尾随换行符 -e 启用解释反斜杠的转义功能 -E 禁用解释反斜杠的转义功能(默认) --he ...
- (转)Oracle存储过程中的事务
本文转载自:http://www.cnblogs.com/linjiqin/archive/2011/04/18/2019990.html 1.事务用于确保数据的一致性,由一组相关的DML语句组成,该 ...
- monolog 应该是世界上最好的日志插件了
引入 composer require monolog/monolog 官网 https://github.com/Seldaek/monolog 创建工具类 <?php /** * Creat ...
- Maria数据库
项目上要进行数据库选型,业务上来讲,数据是非常结构化的数据,使用传统关系数据库更适合:另外项目采用微服务框架,每个服务的数据库应该尽可能轻量级, 最后考虑Maria数据库. MariaDB简介: Ma ...
- js日期date对象
js日期 日期对象的一些属性和方法 var date = new Date() date.toString() // "Tue Jan 29 2019 22:58:13 GMT+0800 ( ...
- springboot成神之——Basic Auth应用
本文介绍Basic Auth在spring中的应用 目录结构 依赖 入口DemoApplication 验证Authenication 配置WebSecurityConfig 控制器TestContr ...
- Python Twisted系列教程4:由Twisted支持的诗歌客户端
作者:dave@http://krondo.com/twisted-poetry/ 译者:杨晓伟(采用意译) 你可以在这里从头开始阅读这个系列. 第一个twisted支持的诗歌服务器 尽管Twist ...
- numpy的一些用法
安装numpy windows安装pip即可,具体方法参考pip官网 http://pip-cn.readthedocs.io/en/latest/installing.html 安装方法:pip i ...
- Stars(树状数组单点更新)
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- Leetcode:Task Scheduler分析和实现
题目大意:提供k个任务,这些任务没有依赖关系(即可以任意调度).CPU完成一个任务需要耗时一个时间片段,当执行完一个任务后,相同的任务必须在n个时间片段才能得以执行.请问CPU通过调度最快能在多少时间 ...