示例#1
0
 private void SetHeaderText(Range rang, string headertxt)
 {
     rang.set_MergeCells(true);
     rang.Value2 = headertxt;
     rang.set_HorizontalAlignment(XlHAlign.xlHAlignCenter);
     rang.set_VerticalAlignment(XlVAlign.xlVAlignCenter);
     rang.BorderAround(1, XlBorderWeight.xlThin, XlColorIndex.xlColorIndexAutomatic, Missing.Value);
 }
    private void writeInCell(Excel.Worksheet theSheet, string cell, string tablename, string column, int tablerow)
    {
        Excel.Range theRange = theSheet.Cells.get_Range(cell, cell);

        //theRange.WrapText = true;
        string theExitvalue = "";

        if (theRange.Value2 != null)
        {
            theExitvalue = theRange.Value2.ToString();
        }
        else
        {
            theExitvalue = "";
        }

        try
        {
            if (tablename != "")
            {
                if (theExitvalue.ToString().Trim() == "")
                {
                    // theRange.Value2 = theRepDS.Tables[tablename].Rows[0][column].ToString();
                    theRange.Value2 = theRepDS.Tables[tablename].Rows[tablerow][column].ToString();
                }
                else
                {
                    // theRange.Value2 = theExitvalue + "  " + theRepDS.Tables[tablename].Rows[0][column].ToString();
                    theRange.Value2 = theExitvalue + "  " + theRepDS.Tables[tablename].Rows[tablerow][column].ToString();
                }
            }
            else
            {
                if (theExitvalue.ToString().Trim() == "")
                {
                    theRange.Value2 = column;
                }
                else
                {
                    theRange.Value2 = theExitvalue + "  " + column;
                }
            }
            if (isvisitSheet)
            {
                theRange.EntireColumn.AutoFit();
            }
            releaseObject(theRange);
        }
        catch (Exception err)
        {
            MsgBuilder theBuilder = new MsgBuilder();
            theBuilder.DataElements["MessageText"] = err.Message.ToString();
            IQCareMsgBox.Show("#C1", theBuilder, this);
            return;
        }
    }
示例#3
0
        private void writeInCell(Excel.Spreadsheet theSheet, string cell, string tablename, string column)
        {
            Excel.Range theRange = theSheet.Cells.get_Range(cell, cell);
            //theRange.Value2
            //theRange.WrapText = true;
            string theExitvalue = "";

            if (theRange.Value2 != null)
            {
                theExitvalue = theRange.Value2.ToString();
            }
            else
            {
                theExitvalue = "";
            }
            if ((ddQuarter.SelectedValue.ToString() != "0") && (txtyears.Text != ""))
            {
                try
                {
                    if (tablename != "")
                    {
                        if (theExitvalue.ToString().Trim() == "")
                        {
                            theRange.Value2 = theRepQuarterDS.Tables[tablename].Rows[0][column].ToString();
                        }
                        else
                        {
                            theRange.Value2 = theExitvalue + "  " + theRepQuarterDS.Tables[tablename].Rows[0][column].ToString();
                        }
                    }
                    else
                    {
                        if (theExitvalue.ToString().Trim() == "")
                        {
                            theRange.Value2 = column;
                        }
                        else
                        {
                            theRange.Value2 = theExitvalue + "  " + column;
                        }
                    }
                }
                catch (Exception err)
                {
                    MsgBuilder theBuilder = new MsgBuilder();
                    theBuilder.DataElements["MessageText"] = err.Message.ToString();
                    IQCareMsgBox.Show("#C1", theBuilder, this);
                    return;
                }
            }

            else if ((ddMonth.SelectedValue.ToString() != "0") && (txtYear.Text != ""))
            {
                try
                {
                    if (tablename != "")
                    {
                        if (theExitvalue.ToString().Trim() == "")
                        {
                            theRange.Value2 = theRepDS.Tables[tablename].Rows[0][column].ToString();
                        }
                        else
                        {
                            theRange.Value2 = theExitvalue + "  " + theRepDS.Tables[tablename].Rows[0][column].ToString();
                        }
                    }
                    else
                    {
                        if (theExitvalue.ToString().Trim() == "")
                        {
                            theRange.Value2 = column;
                        }
                        else
                        {
                            theRange.Value2 = theExitvalue + "  " + column;
                        }
                    }
                }

                catch (Exception err)
                {
                    MsgBuilder theBuilder = new MsgBuilder();
                    theBuilder.DataElements["MessageText"] = err.Message.ToString();
                    IQCareMsgBox.Show("#C1", theBuilder, this);
                    return;
                }
            }
        }