public void CopyThreeKVData(ExcelUtility sourceEx, int sourceIndex, ExcelUtility destiEx, int destiIndex, int startSourceRowIndex, int columnIndex, int startDestiRowIndex, string style, int standardRowIndex, string range, int pattern, out bool sc) { bool checkClear; double temp_double = 0.0; string text; MSExcel.Range rr = null; KVCriterion dataCri = KVCriterion.Null; sc = true; //规范 rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, DataUtility.DataUtility.PositionString(13, columnIndex), out checkClear); text = rr.Text.ToString().Trim(); rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(13, columnIndex), out checkClear); rr.Value2 = text; //标准值 sourceEx.GetCriterion(sourceEx.ExcelWorkbook, sourceIndex, columnIndex, true, out text, out dataCri); //仪器滤片 if (standardRowIndex > 12) { rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, DataUtility.DataUtility.PositionString(standardRowIndex, columnIndex), out checkClear); if (rr != null) { text = rr.Text.ToString().Trim(); rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(15, columnIndex), out checkClear); rr.Value2 = text; } else { rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(15, columnIndex), out checkClear); rr.Value2 = @"/"; } } else { rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(15, columnIndex), out checkClear); rr.Value2 = @"/"; } //复制数据 if (style == "") { for (int i = 0; i < 3; i++) { rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear); if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString())) { sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, @"/", out checkClear); sourceEx.ExcelWorkbook.Save(); sourceEx.ExcelWorkbook.Saved = true; text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear).Trim(); } else { text = rr.Value2.ToString().Trim(); } if (double.TryParse(text, out temp_double) || text == @"/") { destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, startDestiRowIndex + i, columnIndex, text, out checkClear); } else { AddException(@"第" + columnIndex + "列第" + (startSourceRowIndex + i).ToString() + "行不包含有效数据", true); sc = false; } } } else { for (int i = 0; i < 3; i++) { rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear); if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString())) { sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, @"/", out checkClear); sourceEx.ExcelWorkbook.Save(); sourceEx.ExcelWorkbook.Saved = true; text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear).Trim(); } else { text = rr.Value2.ToString().Trim(); } if (double.TryParse(text, out temp_double) || text == @"/") { destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, startDestiRowIndex + i, columnIndex, text, style, out checkClear); } else { AddException(@"第" + columnIndex + "列第" + (startSourceRowIndex + i).ToString() + "行不包含有效数据", true); sc = false; } } } }
public DataStruct CopyThreeCTData(ExcelUtility sourceEx, int sourceIndex, ExcelUtility destiEx, int destiIndex, int startSourceRowIndex, int columnIndex, int startDestiRowIndex, string style, int standardRowIndex, string range, int pattern, out bool sc) { bool checkClear; bool conti = true; double temp_double = 0.0; double diValue = 0.00001; string text; MSExcel.Range rr = null; DoseCriterion dataCri = DoseCriterion.Null; sc = true; conti = TestFlag(sourceEx, sourceIndex, startSourceRowIndex, columnIndex); if (conti) { //确定数据的规范 if (sourceEx.GetCriterion(sourceEx.ExcelWorkbook, sourceIndex, columnIndex, true, out text, out dataCri)) { //规范 rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, DataUtility.DataUtility.PositionString(13, columnIndex), out checkClear); text = rr.Text.ToString().Trim(); //rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(13, sourceEx.GetColumnByCriterion(dataCri, 2)), DataUtility.DataUtility.PositionString(13, sourceEx.GetColumnByCriterion(dataCri, 2) + 1), out checkClear); rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(13, columnIndex), DataUtility.DataUtility.PositionString(13, columnIndex + 1), out checkClear); rr.Value2 = text; //电压写入14行 destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, 14, columnIndex, dataCri.Voltage, out checkClear); //半值层写入15行 destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, 15, columnIndex, dataCri.HalfValueLayer, out checkClear); //标准值 if (standardRowIndex > 12) { rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, DataUtility.DataUtility.PositionString(standardRowIndex, columnIndex), out checkClear); text = rr.Text.ToString().Trim(); //rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(16, sourceEx.GetColumnByCriterion(dataCri, 2)), DataUtility.DataUtility.PositionString(16, sourceEx.GetColumnByCriterion(dataCri, 2) + 1), out checkClear); rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, DataUtility.DataUtility.PositionString(16, columnIndex), DataUtility.DataUtility.PositionString(16, columnIndex + 1), out checkClear); rr.Value2 = text; if (double.TryParse(text, out temp_double)) { diValue = temp_double; } //destiEx.WriteValue(destiIndex, 16, columnIndex, text, @"0.00000000_", out checkClear); } //复制数据 int count = 0; double daValue = 0; if (style == "") { for (int i = 0; i < 3; i++) { rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear); if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString())) { sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, @"/", out checkClear); sourceEx.ExcelWorkbook.Save(); sourceEx.ExcelWorkbook.Saved = true; text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear).Trim(); } else { text = rr.Value2.ToString().Trim(); } if (double.TryParse(text, out temp_double) || text == @"/") { //destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, startDestiRowIndex + i, sourceEx.GetColumnByCriterion(dataCri, 2), text, out checkClear); destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, startDestiRowIndex + i, columnIndex, text, out checkClear); if (text != @"/") { count++; daValue += temp_double; } } else { AddException(@"第" + columnIndex + "列第" + (startSourceRowIndex + i).ToString() + "行不包含有效数据", true); sc = false; } } if (count > 0) { daValue /= count; return new DataStruct(daValue, diValue, range, pattern); } } else { for (int i = 0; i < 3; i++) { rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear); if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString())) { sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, @"/", out checkClear); sourceEx.ExcelWorkbook.Save(); sourceEx.ExcelWorkbook.Saved = true; text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, startSourceRowIndex + i, columnIndex, out checkClear).Trim(); } else { text = rr.Value2.ToString().Trim(); } if (double.TryParse(text, out temp_double) || text == @"/") { //destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, startDestiRowIndex + i, sourceEx.GetColumnByCriterion(dataCri, 2), text, "", out checkClear); destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, startDestiRowIndex + i, columnIndex, text, style, out checkClear); if (text != @"/") { count++; daValue += temp_double; } } else { AddException(@"第" + columnIndex + "列第" + (startSourceRowIndex + i).ToString() + "行不包含有效数据", true); sc = false; } } if (count > 0) { daValue /= count; return new DataStruct(daValue, diValue, range, pattern); } } } else { AddException("规范内容有误:" + text, true); } } sc = false; return null; }