Esempio n. 1
0
        public static 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)
        {
            double temp_double = 0.0;
            string text;
            MSExcel.Range rr = null;
            KVCriterion dataCri = KVCriterion.Null;

            sc = true;

            //规范
            rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(13, columnIndex));
            text = rr.Text.ToString().Trim();
            rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, new ExcelPosition(13, columnIndex));
            rr.Value2 = text;

            //标准值
            sourceEx.GetCriterion(sourceEx.ExcelWorkbook, sourceIndex, columnIndex, true, out text, out dataCri);

            //仪器滤片
            if (standardRowIndex > 12)
            {
                rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(standardRowIndex, columnIndex));
                if (rr != null)
                {
                    text = rr.Text.ToString().Trim();
                    rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, new ExcelPosition(15, columnIndex));
                    rr.Value2 = text;
                }
                else
                {
                    rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, new ExcelPosition(15, columnIndex));
                    rr.Value2 = @"/";
                }
            }
            else
            {
                rr = destiEx.GetRange(destiEx.ExcelWorkbook, destiIndex, new ExcelPosition(15, columnIndex));
                rr.Value2 = @"/";
            }

            ExcelPosition position;

            //复制数据
            if (style == "")
            {
                for (int i = 0; i < 3; i++)
                {
                    position = new ExcelPosition(startSourceRowIndex + i, columnIndex);
                    rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, position);
                    if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString()))
                    {
                        sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, position, @"/");
                        sourceEx.ExcelWorkbook.Save();
                        sourceEx.ExcelWorkbook.Saved = true;
                        text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, position);
                    }
                    else
                    {
                        text = rr.Value2.ToString().Trim();
                    }

                    if (double.TryParse(text, out temp_double) || text == @"/")
                    {
                        destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, position, text);
                    }
                    else
                    {
                        LogHelper.AddException(position.PositionString + "不包含有效数据", true);
                        sc = false;
                    }
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    position = new ExcelPosition(startSourceRowIndex + i, columnIndex);
                    rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, position);
                    if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString()))
                    {
                        sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, position, @"/");
                        sourceEx.ExcelWorkbook.Save();
                        sourceEx.ExcelWorkbook.Saved = true;
                        text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, position);
                    }
                    else
                    {
                        text = rr.Value2.ToString().Trim();
                    }

                    if (double.TryParse(text, out temp_double) || text == @"/")
                    {
                        destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, position, text, style);
                    }
                    else
                    {
                        LogHelper.AddException(position.PositionString + "不包含有效数据", true);
                        sc = false;
                    }
                }
            }
        }
Esempio n. 2
0
        public static 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 conti = true;
            double temp_double = 0.0;
            double diValue = 0.00001;
            string text;
            MSExcel.Range rr = null;
            NormalDoseCriterion dataCri = NormalDoseCriterion.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, new ExcelPosition(13, columnIndex));
                    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, new ExcelPosition(13, columnIndex), new ExcelPosition(13, columnIndex + 1));
                    rr.Value2 = text;
                    //电压写入14行
                    destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, new ExcelPosition(14, columnIndex), dataCri.Voltage);
                    //半值层写入15行
                    destiEx.WriteValue(destiEx.ExcelWorkbook, destiIndex, new ExcelPosition(15, columnIndex), dataCri.HalfValueLayer);

                    //标准值
                    if (standardRowIndex > 12)
                    {
                        rr = sourceEx.GetRange(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(standardRowIndex, columnIndex));
                        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, new ExcelPosition(16, columnIndex), new ExcelPosition(16, columnIndex + 1));
                        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, new ExcelPosition(startSourceRowIndex + i, columnIndex));
                            if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString()))
                            {
                                sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(startSourceRowIndex + i, columnIndex), @"/");
                                sourceEx.ExcelWorkbook.Save();
                                sourceEx.ExcelWorkbook.Saved = true;
                                text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(startSourceRowIndex + i, columnIndex));
                            }
                            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, new ExcelPosition(startDestiRowIndex + i, columnIndex), text);

                                if (text != @"/")
                                {
                                    count++;
                                    daValue += temp_double;
                                }
                            }
                            else
                            {
                                LogHelper.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, new ExcelPosition(startSourceRowIndex + i, columnIndex));
                            if (rr.Value2 == null || string.IsNullOrWhiteSpace(rr.Value2.ToString()))
                            {
                                sourceEx.WriteValue(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(startSourceRowIndex + i, columnIndex), @"/");
                                sourceEx.ExcelWorkbook.Save();
                                sourceEx.ExcelWorkbook.Saved = true;
                                text = sourceEx.GetText(sourceEx.ExcelWorkbook, sourceIndex, new ExcelPosition(startSourceRowIndex + i, columnIndex));
                            }
                            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, new ExcelPosition(startDestiRowIndex + i, columnIndex), text, style);

                                if (text != @"/")
                                {
                                    count++;
                                    daValue += temp_double;
                                }
                            }
                            else
                            {
                                LogHelper.AddException(@"第" + columnIndex + "列第" + (startSourceRowIndex + i).ToString() + "行不包含有效数据", true);
                                sc = false;
                            }
                        }

                        if (count > 0)
                        {
                            daValue /= count;
                            return new DataStruct(daValue, diValue, range, pattern);
                        }
                    }
                }
                else
                {
                    LogHelper.AddException("规范内容有误:" + text, true);
                }
            }
            sc = false;
            return null;
        }