当我没有在线上放任何图片时,我收到错误。 [英] I get an error when I don't put any pictures on the line.
问题描述
byte [] bimage =(byte [])(new ImageConverter()。ConvertTo(dataGridView1 [i,j] .Value,typeof (byte [])));
//放入时所有行都没有显示错误图片,但如果我没有放置镇流器的图片,则会出错。
我尝试过的事情:
byte[] bimage = (byte[])(new ImageConverter().ConvertTo(dataGridView1[i, j].Value, typeof(byte[])));
//all the rows show no error when putting the picture but if I do not put a picture of the ballast, it gives an error.
What I have tried:
private void button5_Click(object sender,EventArgs e)
{
{
Microsoft.Office.Interop.Excel.Application uyg = new Microsoft.Office.Interop.Excel.Application();
uyg.Visible = true;
Microsoft.Office.Interop.Excel.Workbook kitap = uyg.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft。 Office.Interop.Excel.Worksheet sheet1 =(Microsoft.Office.Interop.Excel.Worksheet)kitap.Sheets [1];
Microsoft.Office.Interop.Excel.Range m yRange;
for(int i = 0;我< dataGridView1.Columns.Count; i ++)
{
myRange =(Microsoft.Office.Interop.Excel.Range)sheet1.Cells [1,i + 1];
myRange.Value2 = dataGridView1.Columns [i] .HeaderText;
for(int j = 0; j< dataGridView1.Rows.Count; j ++)
{
myRange =(Microsoft.Office.Interop.Excel.Range)sheet1.Cells [j + 2,i + 1];
if (dataGridView1 [i,j] .GetType()== typeof(DataGridViewImageCell))
{
if(dataGridView1 [i,j] .Value!= null)
{
byte [] bimage =(byte [])(new ImageConverter()。ConvertTo(dataGridView1 [i,j] .Value,typeof(byte [])) );
MemoryStream ms = new MemoryStream(bimage);
Image image = Image.FromStream(ms);
image.Save(@D:\ dosya.jpg);
float Left =(float)(myRange .Left);
float Top =(float)(myRange.Top);
const float ImageSize = 32;
sheet1.Shapes。 AddPicture(@D:\ dosya.jpg,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoCTrue,Left,Top,ImageSize,ImageSize);
myRange.RowHeight = ImageSize + 2;
File.Delete(@D:\ dosya.jpg);
}
else {
myRange.Value2 = dataGridView1 [i,j] .Value;}
}
}
}
}
}
private void button5_Click(object sender, EventArgs e)
{
{
Microsoft.Office.Interop.Excel.Application uyg = new Microsoft.Office.Interop.Excel.Application();
uyg.Visible = true;
Microsoft.Office.Interop.Excel.Workbook kitap = uyg.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Office.Interop.Excel.Worksheet)kitap.Sheets[1];
Microsoft.Office.Interop.Excel.Range myRange;
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[1, i + 1];
myRange.Value2 = dataGridView1.Columns[i].HeaderText;
for (int j = 0; j < dataGridView1.Rows.Count; j++)
{
myRange = (Microsoft.Office.Interop.Excel.Range)sheet1.Cells[j + 2, i + 1];
if (dataGridView1[i, j].GetType() == typeof(DataGridViewImageCell))
{
if (dataGridView1[i, j].Value != null)
{
byte[] bimage = (byte[])(new ImageConverter().ConvertTo(dataGridView1[i, j].Value, typeof(byte[])));
MemoryStream ms = new MemoryStream(bimage);
Image image = Image.FromStream(ms);
image.Save(@"D:\dosya.jpg");
float Left = (float)(myRange.Left);
float Top = (float)(myRange.Top);
const float ImageSize = 32;
sheet1.Shapes.AddPicture(@"D:\dosya.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, ImageSize, ImageSize);
myRange.RowHeight = ImageSize + 2;
File.Delete(@"D:\dosya.jpg");
}
else {
myRange.Value2 = dataGridView1[i, j].Value;}
}
}
}
}
}
推荐答案
您已经在当我没有在线上放任何图片时出现错误。 [ ^ ]。你仍然没有告诉我们错误是什么。
You already posted this at I get an error when I don't put any pictures on the line.[^]. And you are still not telling us what the error is.
这篇关于当我没有在线上放任何图片时,我收到错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!