如何从数据表中导出longblob图像以表现出色?

时间:2019-03-25 16:51:57

标签: c# excel visual-studio

我想导出一些以longblob格式存储在MySQL中的图像,以使其表现出色。 我已经可以从数据表和所有内容中导出数据,但是我无法使图像显示出来。

这是我的出口代码

        {
            ObtenDatosforExcel();
        }

        public void ObtenDatosforExcel()
         {
             conectar.Open();
             DataTable forexcel = new DataTable();
             string consultaex = "select OSeccion as 'Sección', OComentario as 'Comentario', OImagen as 'Foto' from Observaciones order by cast(OSeccion as unsigned), OSeccion;";
             MySqlCommand cmdex = new MySqlCommand(consultaex, conectar);
             MySqlDataAdapter adaptadorex = new MySqlDataAdapter(cmdex);

             adaptadorex.Fill(forexcel);
             forexcelexport(forexcel);
             conectar.Close();
         }
         void forexcelexport(DataTable forexcel)
         {
             Excel.Application oXL; //Se va usar Excel e interactuar con la aplicación
             Excel._Workbook oWB; //Crea el libro
             Excel._Worksheet oSheet;

             try
             {
                 //Inicia Excel y
                 oXL = new Excel.Application();
                 oXL.Visible = true;
                 //Obtiene el libro y la hoja con la que se va a trabajar
                 oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
                 oSheet = (Excel._Worksheet)oWB.ActiveSheet;
                 //Ancho de columnas
                 oSheet.get_Range("A1").ColumnWidth = 30;
                 oSheet.get_Range("B1", "D1").ColumnWidth = 50;
                 //Empieza llenado
                 oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Worksheets.get_Item(1);

        //Acomoda el resto de datos
         for (int i = 0; i < forexcel.Rows.Count; i++)
         {
             for (int j = 0; j < forexcel.Columns.Count; j++)
             {
                 if (forexcel.Rows.GetType() == typeof(Bitmap))
                 {
                     string image = Convert.ToString(oSheet.Cells[i].Value);
                     Excel.Range oRange = (Excel.Range)oSheet.Cells[i + 1, j + 1];
                     float Left = (float)((double)oRange.Left);
                     float Top = (float)((double)oRange.Top);
                     const float ImageSize = 32;
                     oSheet.Shapes.AddPicture(image, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
                     oRange.RowHeight = ImageSize + 2;
                 }
                 else
                 {
                     oSheet.Cells[i + 10, j + 1] = forexcel.Rows[i][j].ToString();
                 }
             }
         }
     }
     catch (Exception theException)
     {
         String errorMessage;
         errorMessage = "Error: ";
         errorMessage = String.Concat(errorMessage, theException.Message);
         errorMessage = String.Concat(errorMessage, " Line: ");
         errorMessage = String.Concat(errorMessage, theException.Source);
         MessageBox.Show(errorMessage, "Error");
     }
 }

请帮助我,我不知道该怎么做。

或者有人可以告诉我其他方法来导出类型为longblob的图像以达到卓越效果。

注意:这不仅是我要导出的图像,还包含表可以包含的所有内容-

0 个答案:

没有答案