private static void word_inster_table(XWPFDocument m_Docx, OutputData bean, int i, String photoPathName) { XWPFTable table = m_Docx.CreateTable(12, 2); CT_Tbl ctbl = m_Docx.Document.body.GetTblArray()[i]; CT_TblPr ctblpr = ctbl.AddNewTblPr(); ctblpr.jc = new CT_Jc(); ctblpr.jc.val = ST_Jc.center; table.Width = 3500; table.GetRow(0).GetCell(0).SetText("设备类型"); table.GetRow(0).GetCell(1).SetText(bean.DeviceType); table.GetRow(1).GetCell(0).SetText("公里标"); table.GetRow(1).GetCell(1).SetText(bean.KilometerMark); table.GetRow(2).GetCell(0).SetText("下行侧向"); table.GetRow(2).GetCell(1).SetText(bean.SideDirection); table.GetRow(3).GetCell(0).SetText("距线路中心距离(m)"); table.GetRow(4).GetCell(0).SetText("经度"); table.GetRow(4).GetCell(1).SetText(bean.Longitude); table.GetRow(5).GetCell(0).SetText("纬度"); table.GetRow(5).GetCell(1).SetText(bean.Latitude); table.GetRow(6).GetCell(0).SetText("杆塔类型"); table.GetRow(6).GetCell(1).SetText(bean.TowerType); table.GetRow(7).GetCell(0).SetText("杆塔高度"); table.GetRow(7).GetCell(1).SetText(bean.TowerHeight); table.GetRow(8).GetCell(0).SetText("天线1方向角"); table.GetRow(8).GetCell(1).SetText(bean.AntennaDirection1); table.GetRow(9).GetCell(0).SetText("天线2方向角"); table.GetRow(9).GetCell(1).SetText(bean.AntennaDirection2); table.GetRow(10).GetCell(0).SetText("天线3方向角"); table.GetRow(10).GetCell(1).SetText(bean.AntennaDirection3); table.GetRow(11).GetCell(0).SetText("天线4方向角"); table.GetRow(11).GetCell(1).SetText(bean.AntennaDirection4); CT_TcPr m_Pr = table.GetRow(2).GetCell(1).GetCTTc().AddNewTcPr(); m_Pr.tcW = new CT_TblWidth(); m_Pr.tcW.w = "3500"; m_Pr.tcW.type = ST_TblWidth.dxa; //设置单元格宽度 XWPFTableRow m_Row = table.InsertNewTableRow(0); XWPFTableCell cell = m_Row.CreateCell(); CT_Tc cttc = cell.GetCTTc(); CT_TcPr ctPr = cttc.AddNewTcPr(); ctPr.gridSpan = new CT_DecimalNumber(); ctPr.gridSpan.val = "2"; cttc.GetPList()[0].AddNewR().AddNewT().Value = "SITE: " + bean.MarkerId; System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(photoPathName); System.IO.FileInfo[] files = dir.GetFiles(); foreach (System.IO.FileInfo file in files) { FileStream gfs = new FileStream(photoPathName + "\\" + file.Name, FileMode.Open, FileAccess.Read); Image image = Image.FromFile(photoPathName + "\\" + file.Name); Double ratio = (Double)image.Width / (Double)image.Height; image.Dispose(); XWPFParagraph gp = m_Docx.CreateParagraph(); gp.SetAlignment(ParagraphAlignment.CENTER); XWPFRun gr = gp.CreateRun(); if (ratio > 1) { gr.AddPicture(gfs, (int)PictureType.JPEG, file.Name, 3555556, 2000000); } else { gr.AddPicture(gfs, (int)PictureType.JPEG, file.Name, 2000000, 3555556); } gfs.Close(); } word_insert_space(3, m_Docx, 100); }
/// <summary> /// 创建数据行 /// </summary> /// <param name="sheet"></param> private void GenerateDataRow(HSSFWorkbook workbook, HSSFSheet sheet) { for (var i = 1; i <= dataList.Count; i++) { var row = (HSSFRow)sheet.GetRow(i); OutputData OutputData = dataList[i - 1]; //序号 ICell cell0 = row.CreateCell(0); cell0.SetCellValue(i); cell0.CellStyle.ShrinkToFit = true; InitDataCellStyle(workbook, cell0); //设备类型 cell0 = row.CreateCell(1); cell0.SetCellValue(OutputData.DeviceType); cell0.CellStyle.ShrinkToFit = true; InitDataCellStyle(workbook, cell0); //公里标 cell0 = row.CreateCell(2); cell0.SetCellValue(OutputData.KilometerMark); cell0.CellStyle.ShrinkToFit = true; InitDataCellStyle(workbook, cell0); //侧向 cell0 = row.CreateCell(3); cell0.SetCellValue(OutputData.SideDirection); cell0.CellStyle.ShrinkToFit = true; InitDataCellStyle(workbook, cell0); //距线路中心距离 cell0 = row.CreateCell(4); cell0.SetCellValue(OutputData.DistanceToRail); cell0.CellStyle.ShrinkToFit = true; InitDataCellStyle(workbook, cell0); //经度 double temp; if (double.TryParse(OutputData.Longitude, out temp)) { cell0 = row.CreateCell(5); cell0.SetCellValue(Double.Parse((OutputData.Longitude))); cell0.CellStyle.ShrinkToFit = true; InitDataCellNumStyle(workbook, cell0); } else { cell0 = row.CreateCell(5); cell0.SetCellValue((OutputData.Longitude)); cell0.CellStyle.ShrinkToFit = true; InitDataCellNumStyle(workbook, cell0); } //纬度 if (double.TryParse(OutputData.Latitude, out temp)) { cell0 = row.CreateCell(6); cell0.SetCellValue(double.Parse(OutputData.Latitude)); cell0.CellStyle.ShrinkToFit = true; InitDataCellNumStyle(workbook, cell0); } else { cell0 = row.CreateCell(6); cell0.SetCellValue(OutputData.Latitude); cell0.CellStyle.ShrinkToFit = true; InitDataCellNumStyle(workbook, cell0); } //备注文本 cell0 = row.CreateCell(7); cell0.SetCellValue(OutputData.Comment); cell0.CellStyle.ShrinkToFit = true; InitDataCellStyle(workbook, cell0); } }