Esempio n. 1
0
File: My.cs Progetto: jane-safr/SMRC
    public static void v_excel(SMRC.DGVt dgv1)
    {
        // if (dgv1.GetClipboardContent() == null || !Clipboard.ContainsText()) return;
        //if (dgv1.GetClipboardContent() == null ) return;
        if (dgv1.RowCount == 0)
        {
            return;
        }
        dgv1.SelectAll();
        dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
        Clipboard.SetDataObject(dgv1.GetClipboardContent());
        Microsoft.Office.Interop.Excel.Application ExlApp = new Microsoft.Office.Interop.Excel.Application();

        Microsoft.Office.Interop.Excel.Workbook WrkBk = ExlApp.Workbooks.Add(System.Reflection.Missing.Value);
        //WrkBk = null;
        //ExlApp.Quit(); ExlApp = null; GC.Collect(); return;
        Microsoft.Office.Interop.Excel.Worksheet WrkSht = (Microsoft.Office.Interop.Excel.Worksheet)WrkBk.ActiveSheet;
        WrkSht.Cells.NumberFormat = "@";
        WrkSht.Cells.ColumnWidth  = 20;
        WrkSht.Cells.WrapText     = true;
        ExlApp.Visible            = true;
        WrkSht.get_Range("A1", "A1").Select();
        //WrkSht.PasteSpecial("Текст", false, false, null, null, null);  // , null --2k3
        if (Clipboard.ContainsText())
        {
            WrkSht.PasteSpecial("Текст", false, false, null, null, null, null);
        }

        object m_objOpt = System.Reflection.Missing.Value;

        //if (dgv1.GetClipboardContent() == null) return;
        //dgv1.CurrentCell = dgv1.FirstDisplayedCell;
        //dgv1.SelectAll();
        //dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
        //Clipboard.SetDataObject(dgv1.GetClipboardContent());
        //Microsoft.Office.Interop.Excel.Workbook WrkBk; Microsoft.Office.Interop.Excel.Worksheet WrkSht;
        //Microsoft.Office.Interop.Excel.Application ExlDb = new Microsoft.Office.Interop.Excel.Application();
        //WrkBk = ExlDb.Workbooks.Add(m_objOpt);
        //WrkSht = (Microsoft.Office.Interop.Excel.Worksheet)WrkBk.ActiveSheet;
        //WrkSht.get_Range("A1", m_objOpt).Select();
        //
        //((Microsoft.Office.Interop.Excel.Range)ExlDb.Selection).ColumnWidth = 20;
        //((Microsoft.Office.Interop.Excel.Range)ExlDb.Selection).WrapText = true;

        //Int32 i = 0;
        //for (Int32 iCol = 1; iCol <= dgv1.Columns.Count; iCol++)
        //{
        //    if (!dgv1.Columns[iCol - 1].Visible)
        //    {

        //        ((Microsoft.Office.Interop.Excel.Range)WrkSht.Columns[iCol + i, m_objOpt]).Delete(Microsoft.Office.Interop.Excel.XlDirection.xlToLeft);
        //        i = i - 1;
        //    }
        //}
        WrkSht.get_Range("A1", "A1").Select();
        ExlApp.Visible = true;
        WrkSht         = null; WrkBk = null; /*ExlApp.Quit();*/
        ExlApp         = null; GC.Collect();
    }
Esempio n. 2
0
File: My.cs Progetto: jane-safr/SMRC
    public static void MySpisok(int nbut1, string Szap1, Form fr, SMRC.DGVt UG)
    {
        DataSet        ds = new DataSet(); DataView dv = new DataView();
        string         str = my.FilterSel(nbut1, null, my.sconn, Szap1);
        SqlDataAdapter da  = new SqlDataAdapter(str, sconn);

        ds.Clear();
        da.Fill(ds);

        UG.DataSource         = ds.Tables[0];
        UG.AllowUserToAddRows = false;
        my.naimDG(my.headStr, UG, my.widthStr);
    }
Esempio n. 3
0
File: My.cs Progetto: jane-safr/SMRC
    public static void naimDG(String sel, SMRC.DGVt Grid, String widthStr)
    {
        int w  = 0;
        int w1 = 0;

        for (int i = 0; i <= Grid.Columns.Count - 1; i++)
        {
            if (w <= sel.Length)
            {
                if (sel.Substring(w, (int)sel.IndexOf(",", w) == -1 ? sel.Length - w : sel.IndexOf(",", w) - w).ToString().Trim() == "0")
                {
                    Grid.Columns[i].Visible = false;
                }
                Grid.Columns[i].HeaderText = sel.Substring(w, (int)(sel.IndexOf(",", w) == -1 ? sel.Length - w : sel.IndexOf(",", w) - w));
                w = (int)sel.IndexOf(",", w) == -1 ? w + 20 : sel.IndexOf(",", w) + 1;
            }
            if (w1 <= widthStr.Length && widthStr.Length != 0)
            {
                Grid.Columns[i].Width = System.Convert.ToInt32(widthStr.Substring(w1, (int)widthStr.IndexOf(",", w1) == -1 ? widthStr.Length - w1 : widthStr.IndexOf(",", w1) - w1));
                w1 = (int)widthStr.IndexOf(",", w1) == -1 ? w1 + 20 : widthStr.IndexOf(",", w1) + 1;
            }
        }
    }