Exemplo n.º 1
0
        public void fncCopiarLinea(string vFich)
        {
            Fichero = vFich;
            AbreExcel(true);
            Visible = false;
            exHoja1 = null;
            exHoja1 = new Microsoft.Office.Interop.Excel.Worksheet();
            exHoja1 = (Microsoft.Office.Interop.Excel.Worksheet)exLibro.Worksheets.get_Item(1);
            Excel.Range oRange;


            oRange = exHoja1.get_Range("2:2");
            oRange.Insert(Excel.XlInsertShiftDirection.xlShiftDown, Type.Missing);
            //oRange = exHoja1.get_Range("1:1");
            //oRange.Select();
            //oRange2 = exHoja1.get_Range("2:2");
            //exHoja1.UsedRange.Copy(oRange2);

            //oRange=oRange.EntireRow;
            //oRange.Insert(Excel.XlInsertShiftDirection.xlShiftDown, Type.Missing);

            //oRange = exHoja1.get_Range("2:2");
            ////exHoja1.UsedRange.Insert(Type.Missing, Type.Missing);
            //exHoja1.Paste(Type.Missing, Type.Missing);
            CierraExcel(true);
            LimpiaExcel();

            //Selection.Copy
            //Rows("2:2").Select
            //Selection.Insert Shift:=xlDown
            //Application.CutCopyMode = False


            //rng = (Excel.Range)rng.Cells[rng.Rows.Count, 1];

            //rng = rng.EntireRow;

            //rng.Insert(Excel.XlInsertShiftDirection.xlShiftDown, missing);
        }
Exemplo n.º 2
0
 public bool BorrarCol(string vCol)
 {
     Microsoft.Office.Interop.Excel.Range oR = exHoja1.get_Range(vCol, vCol);
     oR.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftToLeft);
     return(true);
 }
Exemplo n.º 3
0
        public bool CargaExcel(DataTable dt, int vNumHoja, string Grupo)
        {
            exHoja1 = null;
            try
            {
                exHoja1 = new Microsoft.Office.Interop.Excel.Worksheet();
            }
            catch { }
            exHoja1 = (Microsoft.Office.Interop.Excel.Worksheet)exLibro.Worksheets.get_Item(vNumHoja);
            Excel.Range range;

            decimal vver  = Convert.ToDecimal(exApli.Version.ToString());
            int     vFila = 0;
            int     vCol  = 0;

            try
            {
                if (vver > 80000)
                {
                    frmInformacion.vTotReg = dt.Rows.Count;
                    Application.DoEvents();

                    ADODB.Recordset rs = new ADODB.Recordset();
                    rs = cUtil.ConvertToRecordset(dt);

                    exHoja1.Cells.CopyFromRecordset(rs, vk_MaxRows, vk_MaxColumns);
                    Excel.Range exR = (Excel.Range)exHoja1.Cells[1, 1];
                    Excel.Range row = (Excel.Range)exR.EntireRow;
                    row.Insert(Excel.XlInsertShiftDirection.xlShiftDown, false);
                    foreach (DataColumn dc in dt.Columns)
                    {
                        vFila = 1;
                        vCol  = vCol + 1;
                        exHoja1.Cells[vFila, vCol] = dc.ColumnName;
                    }

                    return(true);
                }
            }
            catch { }

            try
            {
                Excel.Range oRange;

                foreach (DataColumn dc in dt.Columns)
                {
                    vFila = 1;
                    vCol  = vCol + 1;
                    exHoja1.Cells[vFila, vCol] = dc.ColumnName;

                    Application.DoEvents();
                }

                string vGrupNew = "";
                frmInformacion.vTotReg = dt.Rows.Count;
                Application.DoEvents();
                int vContRow = 0;

                object[] vArr = new object[dt.Columns.Count];

                foreach (DataRow dr in dt.Rows)
                {
                    if (frmInformacion.vCancel)
                    {
                        return(true);
                    }
                    vContRow++;
                    if (vContRow % 50 == 0)
                    {
                        frmInformacion.vNReg = vContRow;
                        Application.DoEvents();
                    }
                    vFila = vFila + 1;
                    vCol  = 0;
                    if (Grupo != "")
                    {
                        int vColGrupo = Convert.ToInt16(Grupo);
                        vGrupNew = dr[vColGrupo].ToString();
                        if ((_DatoGrupo != vGrupNew) & (_DatoGrupo != ""))
                        {
                            _DatoGrupo = vGrupNew;
                            Array.Resize(ref FilasG, vContFilasG + 2);
                            FilasG[vContFilasG] = vFila;
                            vContFilasG++;
                            vFila            = vFila + 1;
                            _UltimaFilaGrupo = vFila;
                        }

                        if ((_DatoGrupo == ""))
                        {
                            _DatoGrupo = vGrupNew;
                        }
                    }


                    vArr = dr.ItemArray;
                    string vtFila = "A" + vFila.ToString() + ":" + cUtil.fncLetraCol(vArr.Length) + vFila.ToString();
                    range = exHoja1.get_Range(vtFila);


                    range.set_Value(vk_missing, vArr);
                    _UltimaFila = vFila;
                    _UltimaCol  = vCol;
                }

                if ((_UltimaFilaGrupo != _UltimaFila))
                {
                    vFila      = vFila + 1;
                    _DatoGrupo = vGrupNew;
                    Array.Resize(ref FilasG, vContFilasG + 2);
                    FilasG[vContFilasG] = vFila;
                    vContFilasG++;
                    vFila       = vFila + 1;
                    _UltimaFila = vFila;
                }

                foreach (DataColumn dc in dt.Columns)
                {
                    string vTipo = dt.Columns[vCol - 1].DataType.ToString();
                    if (vTipo == "System.DateTime")
                    {
                        string vRango = vCol + ":" + vCol;

                        oRange = exHoja1.get_Range(vRango);
                        oRange.NumberFormat = "mm/dd/yy;@";
                    }

                    Application.DoEvents();
                }



                _Error = "";
                return(true);
            }
            catch (Exception ex)
            {
                _Error = ex.Message + "-" + ex.Source.ToString();
                return(false);
            }
        }