public TestingProcessResultDto GetResult(SpreadsheetDocument document) { var result = new TestingProcessResultDto(); var propertyDescriptions = PropertyInfoBulider <TestingProcessResultDto> .GetPropertyAttributes(); propertyDescriptions.ForEach(propertyDescription => { this.SetPropertyValue(result, document, propertyDescription); }); this.SetStandardToolValues(result, document); if (result.ProductName == "精密辐射温度计") { this.SetPrecisionProduct(result, document); } else { this.SetStatsticsValues(result, document); } this.SetStatisticsNotes(result, document); this.SetFinallyNotes(result, document); return(result); }
private void SetTestingTools(TestingProcessResultDto result, WordprocessingDocument document) { for (var i = 0; i < result.TestingTools.Count; i++) { var flag = ""; if (i > 0) { flag = (i + 1).ToString(); } var name = "{{TToolName" + flag + "}}"; var text = document.MainDocumentPart.Document.Descendants <Text>().Where(t => t.Text == name).FirstOrDefault(); if (text != null) { text.Text = result.TestingTools[i].Name; } name = "{{TToolTempRange" + flag + "}}"; text = document.MainDocumentPart.Document.Descendants <Text>().Where(t => t.Text == name).FirstOrDefault(); if (text != null) { text.Text = result.TestingTools[i].TempRange; } //{TToolNotSure}} name = "{{TToolNotSure" + flag + "}}"; text = document.MainDocumentPart.Document.Descendants <Text>().Where(t => t.Text == name).FirstOrDefault(); if (text != null) { text.Text = ""; WordHelper.SetKeyWordItalicStyle((Paragraph)text.Parent.Parent, result.TestingTools[i].NotSure, new char[] { 'U', 'k' }); } name = "{{TToolCode" + flag + "}}"; text = document.MainDocumentPart.Document.Descendants <Text>().Where(t => t.Text == name).FirstOrDefault(); if (text != null) { text.Text = result.TestingTools[i].Code; } name = "{{TToolExpiredDesc" + flag + "}}"; text = document.MainDocumentPart.Document.Descendants <Text>().Where(t => t.Text == name).FirstOrDefault(); if (text != null) { text.Text = result.TestingTools[i].ExpiredDesc; } } }
private void SimpleLabelReplacement(TestingProcessResultDto result, WordprocessingDocument document) { var list = WordKeyBulider <TestingProcessResultDto> .GetRepalcedValues(result); document.SearchAndReplaces(list); }
private void SetStatistcisTable(TestingProcessResultDto result, WordprocessingDocument document) { var tables = document.MainDocumentPart.Document.Body.Elements <Table>().ToList(); Table table = null; //statstics-data IEnumerable <TableProperties> tableProperties = document.MainDocumentPart.Document.Body.Descendants <TableProperties>().Where(tp => tp.TableCaption != null); foreach (TableProperties tProp in tableProperties) { if (tProp.TableCaption.Val.InnerText.Equals("statstics-data")) { // do something for table with myCaption table = (Table)tProp.Parent; } } if (table == null) { throw new Exception("未找到填充数据的表格。(caption:statstics-data)"); } var firstDataRow = table.Elements <TableRow>().ToList()[1]; if (result.TestingStatstics.Count == 0) { return; } var addedRow = firstDataRow; for (var i = 0; i < result.TestingStatstics.Count; i++) { var obj = result.TestingStatstics[i]; TableRow newRow; if (i == 0) { newRow = firstDataRow; } else { newRow = (TableRow)firstDataRow.Clone(); } var cells = newRow.Elements <TableCell>().ToList(); this.SetCellValue(cells[0], obj.StandardTemperature.ToString()); this.SetCellValue(cells[1], obj.ResultTemperature); this.SetCellValue(cells[2], obj.Difference); this.SetCellValue(cells[3], obj.ExtendDifference); if (this.Result.光阑直径 == "/") { this.SetCellValue(cells[4], obj.Note); } if (i > 0) { table.InsertAfter(newRow, addedRow); } addedRow = newRow; } if (this.Result.光阑直径 == "/") // if (result.CertificationType == CertificationType.Calibrating) //如果是标准用,那么需要对最后一列进行设置 { //如果是校准的话,那最的一列保留,并进行垂直合并 var rows = table.Elements <TableRow>().ToList().ToList(); //var lastName = ""; var lastNote = ""; for (var i = 0; i < this.Result.TestingStatstics.Count; i++) { var row = rows[i + 1]; MergedCellValues val = MergedCellValues.Restart; var obj = this.Result.TestingStatstics[i]; // if (obj.Name == lastName && obj.Note == lastNote) if (obj.Note == lastNote) { val = MergedCellValues.Continue; } else { val = MergedCellValues.Restart; } var tabelCell = row.Elements <TableCell>().ToList()[4]; var cellProperties = tabelCell.Elements <TableCellProperties>().FirstOrDefault(); if (cellProperties == null) { cellProperties = new TableCellProperties(); tabelCell.Append(cellProperties); } var mergin = cellProperties.Elements <VerticalMerge>().FirstOrDefault(); if (mergin == null) { mergin = new VerticalMerge(); cellProperties.Append(mergin); } mergin.Val = val; if (val == MergedCellValues.Restart) { var paragraph = tabelCell.Elements <Paragraph>().FirstOrDefault(); if (paragraph == null) { paragraph = new Paragraph(); tabelCell.AppendChild(paragraph); } var run = paragraph.Elements <Run>().FirstOrDefault(); if (run == null) { run = new Run(); paragraph.AppendChild(run); } var _text = run.Elements <Text>().FirstOrDefault(); if (_text == null) { _text = new Text(); run.AppendChild(_text); } _text.Text = "黑体辐射源,"; paragraph = (Paragraph)paragraph.Clone(); paragraph.Elements <Run>().First().Elements <Text>().First().Text = "空腔开口直径"; tabelCell.AppendChild(paragraph); paragraph = (Paragraph)paragraph.Clone(); paragraph.Elements <Run>().First().Elements <Text>().First().Text = obj.Note; tabelCell.AppendChild(paragraph); } var verticalAlignment = cellProperties.Elements <TableCellVerticalAlignment>().FirstOrDefault(); if (verticalAlignment == null) { verticalAlignment = new TableCellVerticalAlignment(); cellProperties.Append(verticalAlignment); } verticalAlignment.Val = TableVerticalAlignmentValues.Center; //lastName = obj.Name; lastNote = obj.Note; } } //由于我们分开了标准用和校准的WORD模板,因此不需要再对statistics进行操作了。 }