在一张纸中两次显示相同的数据 [英] Displaying same data twice in one sheet

查看:82
本文介绍了在一张纸中两次显示相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在表1中显示数据的代码.我需要显示相同数据的第二个表.我似乎无法如此显示.我也尝试过修改代码.请帮忙.这是我所拥有的:

Here''s the code to display the data in the table 1. I need to display the second table of the same data. I cannot seem to display as such. I have tried to modify the code as well. Please help. Here''s what I have:

using System;
using System.Collections.Generic;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
namespace UncFunc
{
    class Report
    {
        public void Create(Quantity q)
        {
            Excel.Application objApp;
            Excel._Workbook objBook;
            Excel.Workbooks objBooks;
            Excel.Sheets objSheets;
            Excel._Worksheet objSheet;
            Excel.Range range;
            Excel.Range range1;
            Dictionary<int, Quantity> rootQty = q.RootQuantities;
            //object misValue = System.Reflection.Missing.Value;

            try
            {
                // Instantiate Excel and start a new workbook.
                objApp = new Excel.Application();
                objBooks = objApp.Workbooks;
                objBook = objBooks.Add(Type.Missing);
                objSheets = objBook.Worksheets;
                objSheet = (Excel._Worksheet)objSheets.get_Item(1);
                //Get the range where the starting cell has the address
                //m_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
                range = objSheet.get_Range("A1", Type.Missing);
                range = range.get_Resize(6,10);
               //Create an array.
                string[,] saRet = new string[rootQty.Count+2,10];
                                
                saRet[0, 4] = "Root Quantities";
                saRet[1, 0] = "String";
                saRet[1, 1] = "Symbol";
                saRet[1, 2] = "Limit Description";
                saRet[1, 3] = "Limit Type";
                saRet[1, 4] = "Value";
                saRet[1, 5] = "Limit";
                saRet[1, 6] = "DF";
                saRet[1, 7] = "Divisor";
                saRet[1, 8] = "Std Unc";
                saRet[1, 9] = "Unit";
                //2nd table 
               
                range1 = objSheet.get_Range("A9", Type.Missing);
                range1 = range1.get_Resize(6, 10);// 6,10
                string[,] saRet1 = new string[rootQty.Count+2,10];
                saRet[5, 0] = "New Table";

                int[] aryKeys= new int[rootQty.Keys.Count];
                Dictionary<int,Quantity>.KeyCollection oKeys = rootQty.Keys;
                oKeys.CopyTo(aryKeys, 0);
                //Fill the array.
                for (long iRow = 0; iRow < rootQty.Count; iRow++)
                {
                   
                    //for (long iCol = 0; iCol < 4; iCol++)
                    //{
                        int iKey = aryKeys[iRow];
                        Quantity qty = rootQty[iKey];
                        String sSymbol = qty.Symbol;//column B
                        String sLimitDescription = qty.LimitDescription;// column C
                        //UncType = qty.LimitType.ToString();
                        String sValue = qty.Value.ToString();//column D
                        String sLimit = qty.Limit.ToString();//column E
                        String sDF = qty.df.ToString();//column F
                        String sDivisor = qty.Divisor.ToString();//column G
                        String sStdUnc = qty.StdUnc.ToString();//column H
                        String sUnit = qty.Unit;// column I
                        saRet[iRow+2, 1] = sSymbol;
                        saRet[iRow + 2, 2] = sLimitDescription;
                        //saRet[iRow + 2, 3] = qty.LimitType.ToString();
                        saRet[iRow + 2, 4] = sValue.ToString();
                        saRet[iRow + 2, 5] = sLimit.ToString();
                        saRet[iRow + 2, 6] = sDF.ToString();
                        saRet[iRow + 2, 7] = sDivisor.ToString();
                        saRet[iRow + 2, 8] = sStdUnc.ToString();
                        saRet[iRow + 2, 9] = sUnit;
                
                    //Previous statements                
                        //saRet[iRow+2,0] = sSymbol;
                        //saRet[iRow+2,1] = sValue;
                        //saRet[iRow+2,2] = sStdUnc;
                        //saRet[iRow+2,3] = qty.Unit; //sUnit
                        
                        //Put the row and column address in the cell.
                        //saRet[iRow, iCol] = iRow.ToString() + "|" + iCol.ToString();
                        
                  // }
                }
                
                //Set the range value to the array.
                range.set_Value(Type.Missing, saRet);
                //Replace the _ with space
                string myValue = "X_2";
                string newValue = myValue.Replace("_", "");
                
                
                //Set Subscript
                range = range.get_Resize(6, 9);
                objSheet.get_Range("A1", Type.Missing);
                //range = range.get_Resize(0, 2);
                //range.get_Range(2, 0);
                objSheet.get_Range("A1", "A6").EntireColumn.AutoFit();
                objSheet.get_Range("B3", "B6").get_Characters(2, 2).Font.Subscript = true;//column and character chosen respectively
                //2nd table
                //objSheet.get_Range("A10", "A16").EntireColumn.AutoFit();
                //objSheet.get_Range("B12", "B15").get_Characters(2, 2).Font.Subscript = true;//column and character chosen respectively
                //objSheet.get_Range("B4","B6").Font.Subscript = true;
                //objSheet.get_Range(1, 1).Font.Subscript = true;
                               
                //Set Bold(Added)
                objSheet.get_Range("A1", "J1").Font.Bold = true;
                objSheet.get_Range("A2", "J2").Font.Bold = true;
                //range = range.get_Resize(1, 1);
                //range.get_Characters(1,1).Font.Bold = true;
                //range.Font.Bold = true;
                                
                //Return control of Excel to the user.
                objApp.Visible = true;
                objApp.UserControl = true;

                // Displaying formula in spreadsheet
                //objSheet.get_Range("A8", "A8").FormulaR1C1 = "y = x1 * x2 - x3 / x2 * Quantity.Log(x4)";
                //border for the table
                objSheet.get_Range("A1", "J6").BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlMedium,
                            Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic);
                //grouping of data
                Excel.Range myRange = objSheet.Rows["3:6", Type.Missing] as Excel.Range;
                //myRange.OutlineLevel = 1;
                myRange.Group(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                
                //Save
                objBook.SaveAs("Report Uncertainty.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
                    Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared,
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            catch (Exception theException)
            {
                String errorMessage;
                errorMessage = "Error: ";
                errorMessage = String.Concat(errorMessage, theException.Message);
                errorMessage = String.Concat(errorMessage, " Line: ");
                errorMessage = String.Concat(errorMessage, theException.Source);
                Console.WriteLine(errorMessage, "Error");
            }
        }

推荐答案

我没有看到对表的任何引用.如果您有数据源,则可以克隆它,然后将其应用于第二个控件,如果这对您不起作用,则需要告诉我们原因以及发生了什么.
I don''t see any references to a table. If you have a data source, you can clone it and then apply it to a second control, if this does not work for you, you need to tell us why, and what is happening.


这是数据:
[代码]
使用系统;
使用System.Collections.Generic;
使用System.Text;
命名空间UncFunc
{
课程计划
{
静态void Main(string [] args)
{
//Report report = new Report();
//report.Create();
//Test01();
//Test02();
Test03();
//TestComplex03();
//TestClass1();
}

静态void TestComplex03()
{
Complex a = new Complex(1,0,0,0,0);
复杂物G_r_O =新的复杂物(0.705005644,-0.709201694,0.004055362,0.004049254,0.254009382);
复杂c_t_p_O =新的Complex(1.5,2.99,0.001,0.001,0);
复杂c_r_p_O =新的Complex(0,0,0.001,0.001,0);
Complex eps_O =新的Complex(1,0.01,0.000199993,0.000104739,0.013858672);
复杂eta_O =新的Complex(0,0,1E-10,1E-10,0);
//复杂aaa = G_r_O-c_t_p_O;
//aaa.Evaluate();
复数G_m_O = eps_O *(c_r_p_O + c_t_p_O * G_r_O/(a-c_r_p_O * G_r_O))+ eta_O/a;
//复杂的G_m_O = c_t_p_O * G_r_O;
//复杂的G_m_O = G_r_O-c_t_p_O;
G_m_O.Evaluate();
}
静态无效Test03()
{
数量x1 =新数量("x_1",从x_1读取",规范",UncType.B,10、0.011、1.73、4);
数量x2 =新数量("x_2",输出2",规格",UncType.B,31,0.033,1,10);
数量xA1 =新数量("x_A1",输出A1",规格",UncType.B,10,0.011,1,100);
数量xA2 =新数量("x_A2",读数A2",规格",UncType.B,31,0.033,1,100);
数量x3 =新数量("x_3",更正3",证书",UncType.B,12、0.4、2.4、4);
数量x4 =新数量("x_4",更正4",证书",UncType.B,14、0.5、1.4、100);
数量x5 =新数量("x_5",更正5",证书",UncType.B,1.3、0.04、1、100);
数量x6 =新数量("x_6",更正6",证书",UncType.B,1.6、0.05、1、100);
x1.df = 4;
数量y = x1 * x2-x3/x2 * Quantity.Log(x4);
x1.SetCorrelation(x2,0.7);
x2.SetCorrelation(x3,-0.12);
y.Evaluate();
//生成excel中显示的报告
报告报告=新Report();
report.Create(y);
report.Create(y);

}

静态void Test02()
{
数量dmm =新数量(9.00032,0.0000012,1,4);
数量x1 =新数量(10,0.011,1,100);
数量x2 =新数量(31,0.033,1,100);
数量xA1 =新数量(10,0.011,1,100);
数量xA2 =新数量(31,0.033,1,100);
数量x3 =新数量(12,0.4,1,100);
数量x4 =新数量(14,0.5,1,100);
数量x5 =新数量(1.3,0.04,1,100);
数量x6 =新数量(1.6,0.05,1,100);
//数量y =(x1 + x2)/(x3 + x4)/(x5 + x6);
//数量y01 =(x1 + x2)/(x3 + x4)/(x5 + x6 + x1 + x2);
//y01.Evaluate();
//数量y02 =(x1 + x2)/(Quantity.Pow(x1 + x2-x3,1.2)-x2);
//y02.Evaluate();
x1.df = 4;
数量y03 = x1 * x2-x3/x2;
x1.SetCorrelation(x2,0.8);
y03.Evaluate();
//Report report = new Report();
//report.Create(y03);
数量y = y03;
//数量y2 = y1/(x5 + x6 + x1 + x2);
//数量zz = Quantity.Log(x1);
数量z =新数量(3,0,10000,1)/x1;
z =新数量(3,0,10000,1)/z;
}
静态void Test01()
{
数量A dmm =新数量A(9.00032,0.0000012,1,4);
数量A x1 =新的数量A(10,0.011,1,100);
数量A x2 =新的数量A(31,0.033,1,100);
数量A xA1 =新数量A(10,0.011,1,100);
数量A xA2 =新的数量A(31,0.033,1,100);
数量A x3 =新的数量A(12,0.4,1,100);
数量A x4 =新的数量A(14,0.5,1,100);
数量A x5 =新的数量A(1.3,0.04,1,100);
数量A x6 =新的数量A(1.6,0.05,1,100);
//QuantityA y =(x1 + x2)/(x3 + x4)/(x5 + x6);
//QuantityA y =(x1 + x2)/(x3 + x4)/(x5 + x6 + x1 + x2);
数量A y1 = x1 + x2;
数量A y2 = xA1-xA2;
数量A y = y1/y2;
//QuantityA y1 =(x1 + x2)/(x3 + x4);
//QuantityA y2 = y1/((x5 + x6 + x1 + x2);
//QuantityA zz = QuantityA.Log(x1);
数量A z =新的数量A(3,0,10000,1)/x1;
z =新的QuantityA(3,0,10000,1)/z;
}
静态void TestClass1()
{
Class1 cls =新的Class1();
}
}
}
[/code]

仅用于test03.我不知道如何复制和粘贴第二个表的数组.另一件事是,所显示的表必须具有灵活性,因为它能够根据数据数量自行创建边框.例如,如果我有A-G数据,则边框必须创建一个灵活的边框,如果我有另一个数据H,则它将自动创建自己的边框,换句话说,不会进行硬编码.请帮忙.谢谢.
This is the data:
[code]
using System;
using System.Collections.Generic;
using System.Text;
namespace UncFunc
{
class Program
{
static void Main(string[] args)
{
//Report report = new Report();
//report.Create();
//Test01();
//Test02();
Test03();
//TestComplex03();
//TestClass1();
}

static void TestComplex03()
{
Complex a = new Complex(1, 0, 0, 0, 0);
Complex G_r_O = new Complex(0.705005644, -0.709201694, 0.004055362, 0.004049254, 0.254009382);
Complex c_t_p_O = new Complex(1.5, 2.99, 0.001, 0.001, 0);
Complex c_r_p_O = new Complex(0, 0, 0.001, 0.001, 0);
Complex eps_O = new Complex(1, 0.01, 0.000199993, 0.000104739, 0.013858672);
Complex eta_O = new Complex(0, 0, 1E-10, 1E-10, 0);
//Complex aaa = G_r_O - c_t_p_O;
//aaa.Evaluate();
Complex G_m_O = eps_O * (c_r_p_O + c_t_p_O * G_r_O / (a - c_r_p_O * G_r_O)) + eta_O / a;
//Complex G_m_O = c_t_p_O * G_r_O;
//Complex G_m_O = G_r_O - c_t_p_O;
G_m_O.Evaluate();
}
static void Test03()
{
Quantity x1 = new Quantity("x_1", "Reading from x_1", "Specification", UncType.B, 10, 0.011, 1.73, 4);
Quantity x2 = new Quantity("x_2", "Output 2", "Specification", UncType.B, 31, 0.033, 1, 10);
Quantity xA1 = new Quantity("x_A1", "Output A1", "Specification", UncType.B, 10, 0.011, 1, 100);
Quantity xA2 = new Quantity("x_A2", "Reading A2", "Specification", UncType.B, 31, 0.033, 1, 100);
Quantity x3 = new Quantity("x_3", "Correction 3", "Certificate", UncType.B, 12, 0.4, 2.4, 4);
Quantity x4 = new Quantity("x_4", "Correction 4", "Certificate", UncType.B, 14, 0.5, 1.4, 100);
Quantity x5 = new Quantity("x_5", "Correction 5", "Certificate", UncType.B, 1.3, 0.04, 1, 100);
Quantity x6 = new Quantity("x_6", "Correction 6", "Certificate", UncType.B, 1.6, 0.05, 1, 100);
x1.df = 4;
Quantity y = x1 * x2 - x3 / x2 * Quantity.Log(x4);
x1.SetCorrelation(x2, 0.7);
x2.SetCorrelation(x3, -0.12);
y.Evaluate();
// to generate the report shown in excel
Report report = new Report();
report.Create(y);
report.Create(y);

}

static void Test02()
{
Quantity dmm = new Quantity(9.00032, 0.0000012, 1, 4);
Quantity x1 = new Quantity(10, 0.011, 1, 100);
Quantity x2 = new Quantity(31, 0.033, 1, 100);
Quantity xA1 = new Quantity(10, 0.011, 1, 100);
Quantity xA2 = new Quantity(31, 0.033, 1, 100);
Quantity x3 = new Quantity(12, 0.4, 1, 100);
Quantity x4 = new Quantity(14, 0.5, 1, 100);
Quantity x5 = new Quantity(1.3, 0.04, 1, 100);
Quantity x6 = new Quantity(1.6, 0.05, 1, 100);
//Quantity y = (x1 + x2) / (x3 + x4) / (x5 + x6);
//Quantity y01 = (x1 + x2) / (x3 + x4) / (x5 + x6 + x1 + x2);
//y01.Evaluate();
//Quantity y02 = (x1 + x2) / (Quantity.Pow(x1 + x2 - x3, 1.2) - x2);
//y02.Evaluate();
x1.df = 4;
Quantity y03 = x1 * x2 - x3 / x2;
x1.SetCorrelation(x2, 0.8);
y03.Evaluate();
//Report report = new Report();
//report.Create(y03);
Quantity y = y03;
//Quantity y2 = y1 / (x5 + x6 + x1 + x2);
//Quantity zz = Quantity.Log(x1);
Quantity z = new Quantity(3, 0, 10000, 1) / x1;
z = new Quantity(3, 0, 10000, 1) / z;
}
static void Test01()
{
QuantityA dmm = new QuantityA(9.00032, 0.0000012, 1, 4);
QuantityA x1 = new QuantityA(10, 0.011, 1, 100);
QuantityA x2 = new QuantityA(31, 0.033, 1, 100);
QuantityA xA1 = new QuantityA(10, 0.011, 1, 100);
QuantityA xA2 = new QuantityA(31, 0.033, 1, 100);
QuantityA x3 = new QuantityA(12, 0.4, 1, 100);
QuantityA x4 = new QuantityA(14, 0.5, 1, 100);
QuantityA x5 = new QuantityA(1.3, 0.04, 1, 100);
QuantityA x6 = new QuantityA(1.6, 0.05, 1, 100);
//QuantityA y = (x1 + x2) / (x3 + x4) / (x5 + x6);
//QuantityA y = (x1 + x2) / (x3 + x4) / (x5 + x6 + x1 + x2);
QuantityA y1 = x1 + x2;
QuantityA y2 = xA1 - xA2;
QuantityA y = y1 / y2;
//QuantityA y1 = (x1 + x2) / (x3 + x4);
//QuantityA y2 = y1 / (x5 + x6 + x1 + x2);
//QuantityA zz = QuantityA.Log(x1);
QuantityA z = new QuantityA(3, 0, 10000, 1) / x1;
z = new QuantityA(3, 0, 10000, 1) / z;
}
static void TestClass1()
{
Class1 cls = new Class1();
}
}
}
[/code]

only for test03 is needed. I have no idea on how to copy and paste that array for the second table. Another thing is that, the table displayed has to be flexible in the sense that it is able to create a border by itself depending on the number of data. For example, if i have A-G data, the border has to create a border that is flexible and if i have another data, H, then it will create its own automatically, in other words, no hardcoded. Please help. Thanks.


这篇关于在一张纸中两次显示相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆