Write a picture to the function c # .NET in Excel

xiaoxiao2021-03-06  37

First, add an Excel reference

Run the following function

1, generate related objects

2, read the pixels of the picture in turn, then write to the Excel Cell corresponding to the cross-sectional target

3. Change the cell size in Excel.

note:

EXCEL cell longest IV = (8 1 1) * 26 (15 1) = 276

And the background color of Excel is only 50, and the figure shows the color loss.

Private void loopn ()

{

//Excel._application

Excel.ApplicationClass EAPP = New Excel.ApplicationClass ();

EAPP.Visible = True;

Excel.Workbook ebook;

eBook = EAPP.Workbooks.add (True);

Excel.Worksheet eWorksheet = (Excel.Worksheet) ebook.activesheet;

Excel.range EregE;

eWorksheet.Activate ();

Bitmap mybitmap = new bitmap (@ "E: /EXERCISE/PhotoExcel_net/test.jpg");

Try

{

For (int N = 0; n

{

For (int m = 0; M

{

Try

{

Color Pixelcolor = mybitmap.getpixel (m, n);

ERANGE = (Excel.Range) eworksheet.cells [n 1, m 1];

ERANGE.INTERIOR.COLOR = (int) pixelcolor.toargb ();

}

Catch

{

}

}

}

}

Catch (Exception EX)

{

Messagebox.show (ex.Message.toString ());

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-64631.html

New Post(0)