C# 生成word 文档 代码 外加 IIS报错解决方案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VanCloud.HPCCloud.UserManager;
using VanCloud.HPCCloud.ReportManager;
using System.IO;
using System.Drawing;
using Microsoft.Office.Interop.Word;
using VanCloud.HPCCloud.DataReport;
using VanCloud.HPCCloud.SystemConfig;
using System.Text; namespace SimCloud.Admin
{ public partial class GenerateReport : System.Web.UI.Page
{
log4net.ILog log = log4net.LogManager.GetLogger(typeof(GenerateReport)); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetAllGroup();
}
} /// <summary>
/// confirm click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnConfirm_Click(object sender, EventArgs e)
{
try
{
DateTime startTime = DateTime.MinValue;
if (!string.IsNullOrEmpty(txtFromDt.Text.Trim()))
{
if (!DateTime.TryParse(txtFromDt.Text.Trim(), out startTime))
{
lblErrorMessage.Text = "TimeFormatError";
return;
}
}
DateTime endTime = DateTime.Now.Date;
if (!string.IsNullOrEmpty(txtToDt.Text.Trim()))
{
if (!DateTime.TryParse(txtToDt.Text.Trim(), out endTime))
{
lblErrorMessage.Text = "TimeFormatError";
return;
}
}
if (startTime.CompareTo(endTime) > )
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('开始时间不能大于结束时间')", true);
return;
}
TimeSpan s = new TimeSpan(endTime.Ticks - startTime.Ticks); if (endTime.Date >= DateTime.Now.Date || startTime.Date >= DateTime.Now.Date)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('当天和当天之后的日期不能选择')", true);
return;
} if (s.TotalDays >= )
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('时间不能大于一个月')", true);
return;
} string start = "开始" + DateTime.Now.ToString();
try
{
CreateWordFile(startTime, endTime);
}
catch (Exception ex)
{
log.Error(ex);
}
string end = "结束" + DateTime.Now.ToString(); // ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "onekey", "alert('Word报表生成成功" + start + "" + end + "!')", true);
log.Info("Word报表生成成功" + start + "" + end + "!");
lblErrorMessage.Text = "";
}
catch (Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
} } public void CreateWordFile(DateTime startTime, DateTime endTime)
{ System.Data.DataTable dt = new ReportUtilityFactory(VanCloud.HPCCloud.HPCJobManager.SystemHPCTypeEnum.All, "VanCloud.HPCCloud.DataReport.Properties.Settings.HPCReportingConnectionString", CommonConfig.SystemBasicInfo.LinuxRestAPIPath).GetHistryJobListForServiceReport_SHDQ(startTime, endTime, this.ddlGroupName.SelectedValue);
UserPermission userPerm = new UserPermission("SimCloudConnectionString");
userPerm.Domain = CommonConfig.SystemBasicInfo.DomainNames[];
System.Data.DataTable dtUser = userPerm.GetUsersList();
string groupname = this.ddlGroupName.SelectedItem.Text;
groupname = groupname.Substring(groupname.IndexOf('\\')+);
userPerm.GroupName = groupname;
MonthReport MR = new MonthReport(startTime, endTime, "SimCloudConnectionString", userPerm.Domain, groupname, dt, dtUser);
ReportGroupBasicInfo RGBI = MR.GetGroupBasicInfo();
System.Data.DataTable dtComputerTimeInfo = MR.GetAllComputerTimeInfo();
System.Data.DataTable dtAllQueueInfo = MR.GetAllQueueInfo();
System.Data.DataTable dtAllSystemInfo = MR.GetAllSystemInfo();
System.Data.DataTable dtAllJobsInfo = MR.GetAllJobsInfo();
System.Data.DataTable dtUserComputerTimeInfo = MR.GetUserComputerTimeInfo();
System.Data.DataTable dtUserQueueInfo = MR.GetUserQueueInfo();
System.Data.DataTable dtUserSystemInfo = MR.GetUserSystemInfo();
System.Data.DataTable dtAllDailyInfo = MR.GetAllDailyInfo();
System.Data.DataTable dtAllJobsList = MR.GetAllJobsList(); string message = "";
try
{
Object Nothing = System.Reflection.Missing.Value;
//Directory.CreateDirectory("D:/Report"); //创建文件所在目录
PortalUser puUser = (PortalUser)(Session[@"PortalUser"]);
string name = "Report_" + DateTime.Now.ToString("yyyyMMddHHmmss") + puUser.UserName + ".doc";//文件名
//object filename = "D://Report//" + name; //文件保存路径 object filename = Server.MapPath("~/Admin/Temp/" + name + ""); //创建Word文档
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); WordApp.Selection.ParagraphFormat.LineSpacing = 15f;//设置文档的行间距 //移动焦点并换行
object count = ;
object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara1;
oPara1 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara1.Range.Text = startTime.Year + "年" + startTime.Month + "." + startTime.Day + "-" + endTime.Month + "." + endTime.Day + "上海电气中央研究院服务情况小结";
oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara1.Range.Font.Bold = ;//不加粗
oPara1.Range.Font.Name = "黑体";
oPara1.Range.Font.Size = ;
oPara1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; int start1 = (startTime.Year + "年" + startTime.Month + "." + startTime.Day + "-" + endTime.Month + "." + endTime.Day).Length+;
int end1 = start1 + ;
object oStart = (object)start1;
object oEnd = (object)end1;
Microsoft.Office.Interop.Word.Range rBold = WordDoc.Range(ref oStart, ref oEnd);
rBold.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineSingle;
oPara1.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara2;
oPara1.Range.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineNone;
oPara2 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara2.Range.Text = DateTime.Now.Year + "年" + DateTime.Now.Month + "月" + DateTime.Now.Day + "日";
oPara2.Range.Font.Bold = ;//不加粗
oPara2.Range.Font.Name = "黑体";
oPara2.Range.Font.Size = (float)10.5;
oPara2.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
oPara2.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara3;
oPara3 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara3.Range.Text = "1. 用户基本信息";
oPara3.Range.Font.Bold = ;
oPara3.Range.Font.Name = "黑体";
oPara3.Range.Font.Size = ;
oPara3.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara3.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara4;
oPara4 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara4.Range.Text = "用户:" + RGBI.UserName;
oPara4.Range.Font.Bold = ;
oPara4.Range.Font.Name = "宋体";
oPara4.Range.Font.Size = (float)10.5;
oPara4.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara4.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara5;
oPara5 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara5.Range.Text = "联系人" + RGBI.Linkman;
oPara5.Range.Font.Bold = ;
oPara5.Range.Font.Name = "宋体";
oPara5.Range.Font.Size = (float)10.5;
oPara5.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara5.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara6;
oPara6 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara6.Range.Text = "账号有效时间:" + RGBI.Expires;
oPara6.Range.Font.Bold = ;
oPara6.Range.Font.Name = "宋体";
oPara6.Range.Font.Size = (float)10.5;
oPara6.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara6.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara7;
oPara7 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara7.Range.Text = "账号:" + RGBI.Account;
oPara7.Range.Font.Name = "宋体";
oPara7.Range.Font.Bold = ;
oPara7.Range.Font.Size = (float)10.5;
oPara7.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara7.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara8;
oPara8 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara8.Range.Text = "可用资源:";
oPara8.Range.Font.Name = "宋体";
oPara8.Range.Font.Size = (float)10.5;
oPara8.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara8.Range.InsertParagraphAfter(); WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 CreateTabel1(WordDoc, WordApp, , , RGBI);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara9;
oPara9 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara9.Range.Text = "2.总体使用情况(" + startTime.Year + "年" + startTime.Month + "." + startTime.Day + "-" + endTime.Month + "." + endTime.Day + ")";
oPara9.Range.Font.Bold = ;
oPara9.Range.Font.Name = "黑体";
oPara9.Range.Font.Size = ;
oPara9.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara9.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara10;
oPara10 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara10.Range.Text = "机时使用情况";
oPara10.Range.Font.Name = "宋体";
oPara10.Range.Font.Bold = ;
oPara10.Range.Font.Size = (float)10.5;
oPara10.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara10.Range.InsertParagraphAfter(); for (int i = ; i < ; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
} WordApp.Selection.TypeParagraph();//插入段落 CreateTabel2(WordDoc, WordApp, dtComputerTimeInfo.Rows.Count + , , dtComputerTimeInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara11;
oPara11 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara11.Range.Text = "队列使用情况";
oPara11.Range.Font.Name = "宋体";
oPara11.Range.Font.Bold = ;
oPara11.Range.Font.Size = (float)10.5;
oPara11.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara11.Range.InsertParagraphAfter();
for (int i = ; i < dtComputerTimeInfo.Rows.Count; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
}
CreateTabel3(WordDoc, WordApp, dtAllQueueInfo.Rows.Count + , , dtAllQueueInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara12;
oPara12 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara12.Range.Text = "操作系统情况";
oPara12.Range.Font.Name = "宋体";
oPara12.Range.Font.Bold = ;
oPara12.Range.Font.Size = (float)10.5;
oPara12.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara12.Range.InsertParagraphAfter();
for (int i = ; i < dtAllQueueInfo.Rows.Count; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
}
CreateTabel4(WordDoc, WordApp, dtAllSystemInfo.Rows.Count + , , dtAllSystemInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara13;
oPara13 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara13.Range.Text = "作业规模情况";
oPara13.Range.Font.Name = "宋体";
oPara13.Range.Font.Bold = ;
oPara13.Range.Font.Size = (float)10.5;
oPara13.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara13.Range.InsertParagraphAfter();
for (int i = ; i < dtAllSystemInfo.Rows.Count; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
}
CreateTabel5(WordDoc, WordApp, dtAllJobsInfo.Rows.Count + , , dtAllJobsInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara14;
oPara14 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara14.Range.Text = "3.个体使用情况";
oPara14.Range.Font.Bold = ;
oPara14.Range.Font.Name = "黑体";
oPara14.Range.Font.Size = ;
oPara14.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara14.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara15;
oPara15 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara15.Range.Text = "机时使用情况";
oPara15.Range.Font.Name = "宋体";
oPara15.Range.Font.Bold = ;
oPara15.Range.Font.Size = (float)10.5;
oPara15.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara15.Range.InsertParagraphAfter();
for (int i = ; i < dtAllJobsInfo.Rows.Count; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
}
CreateTabel6(WordDoc, WordApp, dtUserComputerTimeInfo.Rows.Count + , , dtUserComputerTimeInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara16;
oPara16 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara16.Range.Text = "队列使用情况";
oPara16.Range.Font.Name = "宋体";
oPara16.Range.Font.Bold = ;
oPara16.Range.Font.Size = (float)10.5;
oPara16.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara16.Range.InsertParagraphAfter(); for (int i = ; i < dtUserComputerTimeInfo.Rows.Count; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
} CreateTabel7(WordDoc, WordApp, dtUserQueueInfo.Rows.Count + , , dtUserQueueInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara17;
oPara17 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara17.Range.Text = "操作系统情况";
oPara17.Range.Font.Name = "宋体";
oPara17.Range.Font.Bold = ;
oPara17.Range.Font.Size = (float)10.5;
oPara17.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
oPara17.Range.InsertParagraphAfter();
WordApp.Selection.TypeParagraph();//插入段落 for (int i = ; i < dtUserQueueInfo.Rows.Count; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
} CreateTabel8(WordDoc, WordApp, dtUserSystemInfo.Rows.Count + , , dtUserSystemInfo);//创建表格 WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara18;
oPara18 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara18.Range.Text = "4.每日使用情况";
oPara18.Range.Font.Bold = ;
oPara18.Range.Font.Name = "黑体";
oPara18.Range.Font.Size = ;
oPara18.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara18.Range.InsertParagraphAfter();
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara27;
oPara27 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara27.Range.Text = "";
oPara27.Range.Font.Name = "宋体";
oPara27.Range.Font.Bold = ;
oPara27.Range.Font.Size = (float)10.5;
oPara27.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara27.Range.InsertParagraphAfter();
for (int i = ; i < dtUserSystemInfo.Rows.Count ; i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
}
CreateTabel9(WordDoc, WordApp, dtAllDailyInfo.Rows.Count + , , dtAllDailyInfo);//创建表格 Microsoft.Office.Interop.Word.Paragraph oPara19;
oPara19 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara19.Range.Text = "5.异常情况及排队原因";
oPara19.Range.Font.Bold = ;
oPara19.Range.Font.Name = "黑体";
oPara19.Range.Font.Size = ;
oPara19.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara19.Range.InsertParagraphAfter();
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
WordApp.Selection.TypeParagraph();//插入段落 Microsoft.Office.Interop.Word.Paragraph oPara20;
oPara20 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara20.Range.Text = "";
oPara20.Range.Font.Name = "宋体";
oPara20.Range.Font.Bold = ;
oPara20.Range.Font.Size = (float)10.5;
oPara20.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara20.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara21;
oPara21 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara21.Range.Text = "6.本月使用情况分析";
oPara21.Range.Font.Bold = ;
oPara21.Range.Font.Name = "黑体";
oPara21.Range.Font.Size = ;
oPara21.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara21.Range.InsertParagraphAfter();
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 Microsoft.Office.Interop.Word.Paragraph oPara22;
oPara22 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara22.Range.Text = "";
oPara22.Range.Font.Name = "宋体";
oPara22.Range.Font.Bold = ;
oPara22.Range.Font.Size = (float)10.5;
oPara22.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara22.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara23;
oPara23 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara23.Range.Text = "7.用户服务情况";
oPara23.Range.Font.Bold = ;
oPara23.Range.Font.Name = "黑体";
oPara23.Range.Font.Size = ;
oPara23.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara23.Range.InsertParagraphAfter();
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 Microsoft.Office.Interop.Word.Paragraph oPara24;
oPara24 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara24.Range.Text = "";
oPara24.Range.Font.Name = "宋体";
oPara24.Range.Font.Bold = ;
oPara24.Range.Font.Size = (float)10.5;
oPara24.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara24.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara25;
oPara25 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara25.Range.Text = "8.作业列表";
oPara25.Range.Font.Bold = ;
oPara25.Range.Font.Name = "黑体";
oPara25.Range.Font.Size = ;
oPara25.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara25.Range.InsertParagraphAfter();
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点 Microsoft.Office.Interop.Word.Paragraph oPara26;
oPara26 = WordDoc.Content.Paragraphs.Add(ref Nothing);
oPara26.Range.Text = "";
oPara26.Range.Font.Name = "宋体";
oPara26.Range.Font.Bold = ;
oPara26.Range.Font.Size = (float)10.5;
oPara26.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
oPara26.Range.InsertParagraphAfter();
for(int i=;i<dtAllDailyInfo.Rows.Count-;i++)
{
WordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
} CreateTabel10(WordDoc, WordApp, dtAllJobsList.Rows.Count + , , dtAllJobsList);//创建表格 WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing); //message = name + "文档生成成功,以保存到D:CNSI下";
//Response.Write(message); this.HyperLink1.Text = name;
this.HyperLink1.NavigateUrl = "~/Admin/Temp/" + name ;
this.HyperLink1.Visible = true;
}
catch(Exception ex)
{
log.Error(ex.Message);
log.Error(ex.StackTrace);
message = "文件导出异常!";
} } public void CreateTabel(Document WordDoc, Application WordApp, int rows, int cells, string value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Cell(, ).Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Cell(, ).Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Cell(, ).Range.Shading.ForegroundPatternColor = GetColor(u);// Microsoft.Office.Interop.Word.WdColor.wdColorTurquoise;//背景颜色
newTable.Cell(, ).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;//字体颜色
newTable.Cell(, ).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;//字体颜色
newTable.Cell(, ).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;//字体颜色 newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 100f;
newTable.Columns[].Width = 200f; newTable.Cell(, ).Range.Text = "姓名";
newTable.Cell(, ).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
newTable.Cell(, ).Range.Text = "磁盘空间";
newTable.Cell(, ).Range.Text = "队列";
//在表格中增加行
//WordDoc.Content.Tables[1].Rows.Add(ref Nothing);
newTable.Cell(, ).Range.Text = "SECCAHPC/03010100";
newTable.Cell(, ).Range.Text = "1 TB";
newTable.Cell(, ).Range.Text = "Ansys/CFX/Fluent/Nastran/Abaqus"; newTable.Cell(, ).Range.Text = "陈吉";
newTable.Cell(, ).Range.Text = "";
newTable.Cell(, ).Range.Text = ""; newTable.Cell(, ).Range.Text = "SECCAHPC/03010101";
newTable.Cell(, ).Range.Text = "1 TB";
newTable.Cell(, ).Range.Text = "Ansys/CFX/Fluent/Nastran/Abaqus"; newTable.Cell(, ).Range.Text = "张三";
newTable.Cell(, ).Range.Text = "1 TB";
newTable.Cell(, ).Range.Text = "Ansys/CFX/Fluent/Nastran/Abaqus"; newTable.Cell(, ).Merge(newTable.Cell(, )); newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u); newTable.Columns[].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Columns[].Borders.OutsideColor = GetColor(u); //oDoc.Tables[1].Cell(1, 1).Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue;//字体颜色
//newTable.Range.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
}
public void CreateTabel1(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite; newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 240f; newTable.Cell(, ).Range.Text = "CPU核数";
newTable.Cell(, ).Range.Text = "磁盘空间";
newTable.Cell(, ).Range.Text = "队列"; newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; ReportGroupBasicInfo a = (ReportGroupBasicInfo)value;
newTable.Cell(, ).Range.Text = a.Cpu.ToString();
newTable.Cell(, ).Range.Text = a.Storage;
newTable.Cell(, ).Range.Text = a.Solvers; newTable.Cell(, ).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
newTable.Cell(, ).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
newTable.Cell(, ).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
} public void CreateTabel2(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite; newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 160f;
newTable.Columns[].Width = 160f;
newTable.Columns[].Width = 160f; newTable.Cell(, ).Range.Text = "用户目录";
newTable.Cell(, ).Range.Text = "运行作业数";
newTable.Cell(, ).Range.Text = "使用机时(CPU小时)";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value;
int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public void CreateTabel3(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f; newTable.Cell(, ).Range.Text = "队列";
newTable.Cell(, ).Range.Text = "作业数";
newTable.Cell(, ).Range.Text = "机时";
newTable.Cell(, ).Range.Text = "占总机时比例(%)";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value; int i = ; foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public void CreateTabel4(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f; newTable.Cell(, ).Range.Text = "系统";
newTable.Cell(, ).Range.Text = "作业数";
newTable.Cell(, ).Range.Text = "机时";
newTable.Cell(, ).Range.Text = "占总机时比例(%)";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value;
int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public void CreateTabel5(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f;
newTable.Columns[].Width = 120f; newTable.Cell(, ).Range.Text = "核心数";
newTable.Cell(, ).Range.Text = "作业数";
newTable.Cell(, ).Range.Text = "机时";
newTable.Cell(, ).Range.Text = "占总机时比例(%)";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value;
int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public void CreateTabel6(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 150f;
newTable.Columns[].Width = 110f;
newTable.Columns[].Width = 110f;
newTable.Columns[].Width = 110f; newTable.Cell(, ).Range.Text = "用户目录";
newTable.Cell(, ).Range.Text = "姓名";
newTable.Cell(, ).Range.Text = "运行作业数";
newTable.Cell(, ).Range.Text = "使用机时(CPU小时)";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value; int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public void CreateTabel7(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
List<int> Merge=new List<int>();
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;
newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 150f;
newTable.Columns[].Width = 110f;
newTable.Columns[].Width = 110f;
newTable.Columns[].Width = 110f; newTable.Cell(, ).Range.Text = "姓名";
newTable.Cell(, ).Range.Text = "队列";
newTable.Cell(, ).Range.Text = "作业数";
newTable.Cell(, ).Range.Text = "机时";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value; int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
i++;
} int j = ;
int d = ;
for (int k = ; k < dt.Rows.Count - ; k++)
{
if (dt.Rows[k][].ToString() == dt.Rows[k + ][].ToString())
{
if (d == )
{
string name = newTable.Cell(j, ).Range.Text;
newTable.Cell(j, ).Merge(newTable.Cell(j + , ));
d = j;
newTable.Cell(j, ).Range.Text = name;
}
else
{
string name = newTable.Cell(d, ).Range.Text;
newTable.Cell(d, ).Merge(newTable.Cell(j + , ));
newTable.Cell(d, ).Range.Text = name;
}
}
else
{
d = ;
}
j++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u); newTable.Columns[].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Columns[].Borders.OutsideColor = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ; } public void CreateTabel8(Document WordDoc, Application WordApp, int rows, int cells, object value)
{ Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable1 = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable1.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable1.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite;
newTable1.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable1.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable1.Columns[].Width = 114f;
newTable1.Columns[].Width = 90f;
newTable1.Columns[].Width = 90f;
newTable1.Columns[].Width = 90f;
newTable1.Columns[].Width = 96f; newTable1.Cell(, ).Range.Text = "姓名";
newTable1.Cell(, ).Range.Text = "系统";
newTable1.Cell(, ).Range.Text = "作业数";
newTable1.Cell(, ).Range.Text = "机时";
newTable1.Cell(, ).Range.Text = "占总机时比例(%)";
newTable1.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value;
int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable1.Cell(i, ).Range.Font.Bold = ;
newTable1.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable1.Cell(i, ).Range.Text = dr[].ToString();
newTable1.Cell(i, ).Range.Text = dr[].ToString();
newTable1.Cell(i, ).Range.Text = dr[].ToString();
newTable1.Cell(i, ).Range.Text = dr[].ToString();
newTable1.Cell(i, ).Range.Text = dr[].ToString();
i++;
} int j = ;
int d = ;
for (int k = ; k < dt.Rows.Count - ; k++)
{
if (dt.Rows[k][].ToString() == dt.Rows[k + ][].ToString())
{
if (d == )
{
string name = newTable1.Cell(j, ).Range.Text;
newTable1.Cell(j, ).Merge(newTable1.Cell(j + , ));
d = j;
newTable1.Cell(j, ).Range.Text = name;
}
else
{
string name = newTable1.Cell(d, ).Range.Text;
newTable1.Cell(d, ).Merge(newTable1.Cell(j + , ));
newTable1.Cell(d, ).Range.Text = name;
}
}
else
{
d = ;
}
j++;
} newTable1.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable1.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable1.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable1.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable1.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable1.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable1.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable1.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable1.Columns[].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
newTable1.Columns[].Borders.OutsideColor = GetColor(u);
newTable1.Rows.AllowBreakAcrossPages = ; } public void CreateTabel9(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Name = "宋体";
newTable.Rows[].Range.Font.Size = 11f;
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite; newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 65f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 55f;
newTable.Columns[].Width = 60f; newTable.Cell(, ).Range.Text = "日期";
newTable.Cell(, ).Range.Text = "提交作业";
newTable.Cell(, ).Range.Text = "完成作业";
newTable.Cell(, ).Range.Text = "取消作业";
newTable.Cell(, ).Range.Text="最大运行核数";
newTable.Cell(, ).Range.Text = "最大排队核数";
newTable.Cell(, ).Range.Text = "机时";
newTable.Cell(, ).Range.Text = "队列";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter; System.Data.DataTable dt = (System.Data.DataTable)value; int i = ;
foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString(); i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public void CreateTabel10(Document WordDoc, Application WordApp, int rows, int cells, object value)
{
Object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, rows, cells, ref Nothing, ref Nothing);
//设置表格
Color u = Color.FromArgb(, , ); newTable.Rows[].Range.Shading.ForegroundPatternColor = GetColor(u);
newTable.Rows[].Range.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorWhite; newTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
newTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleNone;
newTable.Columns[].Width = 40f;
newTable.Columns[].Width = 40f;
newTable.Columns[].Width = 40f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 60f;
newTable.Columns[].Width = 120f; newTable.Cell(, ).Range.Text = "JobID";
newTable.Cell(, ).Range.Text = "CPU核数";
newTable.Cell(, ).Range.Text = "统计机时";
newTable.Cell(, ).Range.Text = "队列";
newTable.Cell(, ).Range.Text = "提交时刻";
newTable.Cell(, ).Range.Text = "运行时刻";
newTable.Cell(, ).Range.Text = "结束时刻";
newTable.Cell(, ).Range.Text = "作业目录";
newTable.Rows[].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
System.Data.DataTable dt = (System.Data.DataTable)value; int i = ; foreach (System.Data.DataRow dr in dt.Rows)
{
newTable.Cell(i, ).Range.Font.Bold = ;
newTable.Cell(i, ).Range.TwoLinesInOne = Microsoft.Office.Interop.Word.WdTwoLinesInOneType.wdTwoLinesInOneNone;
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString();
newTable.Cell(i, ).Range.Text = dr[].ToString(); i++;
} newTable.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleNone;
newTable.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle;
newTable.Borders[WdBorderType.wdBorderLeft].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderRight].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderBottom].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderTop].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderHorizontal].Color = GetColor(u);
newTable.Borders[WdBorderType.wdBorderVertical].Color = GetColor(u);
newTable.Rows.AllowBreakAcrossPages = ;
} public static void WriteError(string data)
{
try
{
string sPath = "C:\\Log";
if (sPath == null || sPath == "")
{
return;
}
sPath = sPath.TrimEnd('\\'); if (!Directory.Exists(sPath))
{
Directory.CreateDirectory(sPath);
}
data = string.Format("\r\n {0} ", data + DateTime.Now.ToString());
byte[] bytes = UTF8Encoding.UTF8.GetBytes(data);
int length = bytes.Length;
string logfile = Path.Combine(sPath, DateTime.Now.ToString("yyyyMMdd") + ".log");
FileStream w = null;
if (!File.Exists(logfile))
{
using (w = File.Create(logfile)) { }
}
try
{
w = File.Open(logfile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
w.Position = w.Length;
w.Write(bytes, , length);
}
finally
{
if (w != null)
{
w.Close();
}
} }
catch
{
}
} WdColor GetColor(Color c)
{
UInt32 R = 0x1, G = 0x100, B = 0x10000;
return (Microsoft.Office.Interop.Word.WdColor)(R * c.R + G * c.G + B * c.B);
} public void GetAllGroup()
{ GroupPermission GP = new GroupPermission("SimCloudConnectionString");
this.ddlGroupName.DataSource = GP.GetAllGroups(null);
this.ddlGroupName.DataBind();
} /// <summary>
/// intialize the page culture
/// </summary>
protected override void InitializeCulture()
{
if (this.Session["SimCloud_UserCulture"] != null)
{
Page.Culture = Session["SimCloud_UserCulture"].ToString();
Page.UICulture = Session["SimCloud_UserCulture"].ToString();
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(Session["SimCloud_UserCulture"].ToString());
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Session["SimCloud_UserCulture"].ToString());
} base.InitializeCulture();
} public void exportFile(string fileName)
{
string filePath = Server.MapPath("Temp/"+fileName+"");//路径
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
} }
}
解决服务器端不能自动生成Word文件问题,因为已经安装word,则需要配置DCOM: (1.在CMD中运行mmc -32 2.File>Add/Remove Snap-in 3.add "Component Services) 1.在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务" 2:依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置" 3:在"DCOM配置"中找到"Microsoft Word 应用程序",在它上面点击右键,然后点击"属性",弹出"Microsoft Word 应用程序属性"对话框 4:点击"安全"标签,在"启动和激活权限"上点击"自定义",然后点击对应的"编辑"按钮,在弹出的"安全性"对话框中填加一个"NETWORK SERVICE"用户(注意要选择本计算机名),并给它赋予"本地启动"和"本地激活"权限. 5:依然是"安全"标签,在"访问权限"上点击"自定义",然后点击"编辑",在弹出的"安全性"对话框中也填加一个"NETWORK? SERVICE"用户,然后赋予"本地访问"权限. 6.点击"标识"标签,选择"交互式用户
C# word AllowBreakAcrossPages
C# 生成word 文档 代码 外加 IIS报错解决方案的更多相关文章
- 使用java2Word生成Word文档打不开报错 存在非法字符xml
今天也不知道是该吐槽Java2word还是我的eclipse,总之就是使用Java2Word生成文档的时候文档生成没问题,但是生成的Word文档打不开还报错,存在非法字符xml,好扎心.终于找到了解决 ...
- 使用C#动态生成Word文档/Excel文档的程序测试通过后,部署到IIS服务器上,不能正常使用的问题解决方案
使用C#动态生成Word文档/Excel文档的程序功能调试.测试通过后,部署到服务器上,不能正常使用的问题解决方案: 原因: 可能asp.net程序或iis访问excel组件时权限不够(Ps:Syst ...
- ASP.NET生成WORD文档,服务器部署注意事项
网上转的,留查备用,我服务器装的office2007所以修改的是Microsoft Office word97 - 2003 文档这一个. ASP.NET生成WORD文档服务器部署注意事项 1.Asp ...
- PowerDesigner将PDM导出生成WORD文档
PowerDesigner将PDM导出生成WORD文档 环境 PowerDesigner15 1.点击Report Temlates 制作模板 2.如果没有模板,单击New图标创建.有直接双击进入. ...
- velocity模板技术生成word文档
本文介绍採用velocity技术在Java中生成word文档的方法. 1.新建一个word文档,编辑内容例如以下: 2.将上述word文档另存为htm格式的文件 3.新建一个Java Project项 ...
- 将HTML导出生成word文档
前言: 项目开发中遇到了需要将HTML页面的内容导出为一个word文档,所以有了这边随笔. 当然,项目开发又时间有点紧迫,第一时间想到的是用插件,所以百度了下.下面就介绍两个导出word文档的方法. ...
- POI生成word文档完整案例及讲解
一,网上的API讲解 其实POI的生成Word文档的规则就是先把获取到的数据转成xml格式的数据,然后通过xpath解析表单式的应用取值,判断等等,然后在把取到的值放到word文档中,最后在输出来. ...
- PoiDocxDemo【Android将表单数据生成Word文档的方案之二(基于Poi4.0.0),目前只能java生成】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 这个是<PoiDemo[Android将表单数据生成Word文档的方案之二(基于Poi4.0.0)]>的扩展,上一篇是根 ...
- PoiDemo【Android将表单数据生成Word文档的方案之二(基于Poi4.0.0)】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 使用Poi实现android中根据模板文件生成Word文档的功能.这里的模板文件是doc文件.如果模板文件是docx文件的话,请阅读 ...
随机推荐
- mysql系列之5.mysql备份恢复
备份数据: mysqldump #mysqldump -uroot -p123456 test > /test_bak.sql #egrep -v "#|\*|--|^$" ...
- 【题解】CF24D Broken Robots(收敛性)
[题解]CF24D Broken Robots http://codeforces.com/problemset/problem/24/D 解1(不会写,口胡的) 获得一个比较显然的转移式子 \(dp ...
- 洛谷2483 k短路([SDOI2010]魔法猪学院)
题目请戳这里 一句话题意: 给你一张n个节点,m条单向边的图,求1到n第k短的路. emmm,纪念第一个黑题(我是真的菜啊!!) 这题目还是很难的,本蒟蒻只会被洛谷卡掉的A(所以就愉快地特判了),首先 ...
- PHP通过session id 实现session共享和登录验证的代码
先说说,这个机制的用途吧,到现在为止战地知道这个机制有两个方面的用途: 首先,多服务器共享session问题,这个大家应该都能够理解的,当一个网站的用户量过大,就会使用服务器集群,例如专门有一个登录用 ...
- Allegro PCB中添加汉字
注明出处:http://www.cnblogs.com/einstein-2014731/p/5650943.html Cadence用起来比AltiumDesigner要麻烦些,但是也更开放,更灵活 ...
- Step 0: 安装及启动
一.Setting up a Single Node Cluster: http://hadoop.apache.org/docs/r2.6.5/hadoop-project-dist/hadoop- ...
- pkg-config设置
pkg-config在一些源码管理中会被使用到. 介绍 上网查资料,知道了pkg-config这个东西,下面简单介绍一下. pkg-config提供了下面几个功能: 检查库的版本号.如果所需要的库的版 ...
- EASYARM-IMX283 烧写uboot和linux系统
新入手一台EASYARM-IMX283开发板(以下简称IMX823),价格比较便宜,配置也不错. 开发板默认安装了WINCE,我还是决定重新烧写uboot和linux内核. 开发板配套光盘里面有不少烧 ...
- HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )
How many prime numbers Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- 2014暑假ACM训练总结
2014暑假ACM训练总结报告 匆匆之中,一个暑假又过去了,在学校训练的这段日子真的是感觉日子过得好快啊! 时光如箭,日月如梭! 匆忙的学习之中一个暑假就这样结束了,现在就来写一些总结吧,供自己以后阅 ...