Ejemplo n.º 1
0
        /// <summary>
        /// Esporta la produzione che si sta visualizzando in file excel.
        /// </summary>
        private void esportaExcelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (TabellaGenerata)
            {
                Cursor = Cursors.WaitCursor;
                Excel.Application XLApp = new Excel.Application();

                if (XLApp == null)
                {
                    MessageBox.Show("Excel non è installato corettamente nel terminale");
                    return;
                }

                Excel.Workbook  XlWorkBook;
                Excel.Worksheet XlWorkSheet;
                object          misValue = System.Reflection.Missing.Value;

                XlWorkBook  = XLApp.Workbooks.Add(misValue);
                XlWorkSheet = (Excel.Worksheet)XlWorkBook.Worksheets.get_Item(1);


                string[,] tabella = new string[100, 100];
                CompilatoreExcel(XlWorkSheet, DistintaBase.Albero, 1);
                XlWorkSheet.Columns.AutoFit();
                Cursor = Cursors.Default;

                XlWorkBook.Close(true);
                XLApp.Quit();
                Marshal.ReleaseComObject(XLApp);
            }

            else
            {
                MessageBox.Show("Programma la produzione di una distinta base.", "Gestione materiali", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 2
0
        public void enviarExcel()
        {
            Excel.Application XlApp;
            Excel.Workbook    XlWorkBook;
            Excel.Worksheet   XlWorkSheet;
            object            misValue = System.Reflection.Missing.Value;

            //cria planilia temporaria
            XlApp       = new Excel.Application();
            XlWorkBook  = XlApp.Workbooks.Add(misValue);
            XlWorkSheet = (Excel.Worksheet)XlWorkBook.Worksheets.get_Item(1);

            XlWorkSheet.Cells[1, 1]   = "Dados da avaliação";
            XlWorkSheet.Cells[2, 1]   = "Muito Ruim";
            XlWorkSheet.Cells[3, 1]   = "Ruim";
            XlWorkSheet.Cells[4, 1]   = "Médio";
            XlWorkSheet.Cells[5, 1]   = "Bom";
            XlWorkSheet.Cells[6, 1]   = "Muito Bom";
            XlWorkSheet.Cells[7, 1]   = "Ótimo";
            XlWorkSheet.Cells[8, 1]   = "QTD Total votos";
            XlWorkSheet.Cells[9, 1]   = "Média";
            XlWorkSheet.Cells[1, 2]   = "QTD Votos";
            XlWorkSheet.Cells[2, 2]   = mtruim.Text;
            XlWorkSheet.Cells[3, 2]   = label1.Text;
            XlWorkSheet.Cells[4, 2]   = label2.Text;
            XlWorkSheet.Cells[5, 2]   = label3.Text;
            XlWorkSheet.Cells[6, 2]   = mtbom.Text;
            XlWorkSheet.Cells[7, 2]   = otimo.Text;
            XlWorkSheet.Cells[8, 2]   = label8.Text;
            XlWorkSheet.Cells[9, 2]   = label5.Text;
            XlWorkSheet.Cells[1, 3]   = "Relatorio NTP";
            XlWorkSheet.Cells[2, 3]   = "Valor NTP";
            XlWorkSheet.Cells[2, 4]   = label16.Text;
            XlWorkSheet.Cells[6, 3]   = "% de avaliação";
            XlWorkSheet.Cells[7, 3]   = "Baixo";
            XlWorkSheet.Cells[8, 3]   = "medio";
            XlWorkSheet.Cells[9, 3]   = "alto";
            XlWorkSheet.Cells[7, 4]   = label17.Text;
            XlWorkSheet.Cells[8, 4]   = label18.Text;
            XlWorkSheet.Cells[9, 4]   = label19.Text;
            XlWorkSheet.Cells[1, 5]   = "Estrelas";
            XlWorkSheet.Cells[2, 5]   = label6.Text;
            XlWorkSheet.Cells[3, 5]   = label7.Text;
            XlWorkSheet.Cells[1, 6]   = label4.Text;
            XlWorkSheet.Cells[11, 11] = "Os graficos estao sobreposto, arraste para separalos.";
            //erro grafico 1 n aparece e grafico 2 sim como resolver.
            //grafico 2
            Excel.Range chartRange;

            Excel.ChartObjects xlCharts  = (Excel.ChartObjects)XlWorkSheet.ChartObjects(Type.Missing);
            Excel.ChartObject  myChart   = (Excel.ChartObject)xlCharts.Add(100, 180, 500, 300);
            Excel.Chart        chartPage = myChart.Chart;


            chartRange = XlWorkSheet.get_Range("A2", "B7");
            chartPage.SetSourceData(chartRange, misValue);
            chartPage.ChartType = Excel.XlChartType.xlColumnClustered;
            //fim do grafico 1
            //grafico1
            Excel.Range chartRange1;

            Excel.ChartObjects xlCharts1  = (Excel.ChartObjects)XlWorkSheet.ChartObjects(Type.Missing);
            Excel.ChartObject  myChart1   = (Excel.ChartObject)xlCharts1.Add(100, 180, 500, 300);
            Excel.Chart        chartPage1 = myChart1.Chart;


            chartRange1 = XlWorkSheet.get_Range("C7", "d9");
            chartPage1.SetSourceData(chartRange1, misValue);
            chartPage1.ChartType = Excel.XlChartType.xlColumnClustered;



            XlWorkBook.SaveAs(dia + "0" + mes + ano + ".xls",
                              Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            XlWorkBook.Close(true, misValue, misValue);
            XlApp.Quit();
            string folder1 = @"C:/Relatorios/";


            if (!Directory.Exists(folder1))
            {
                //Criamos um com o nome folder
                Directory.CreateDirectory(folder1);
            }

            MessageBox.Show(folder1 + dia + "0" + mes + ano + "xls" + " " + " caso não esteja la verifique em documentos");
        }