Images can be added to a sheet or cell using one of the following methods.
Using this method, the image is added to the sheet and kept at its original size. The upper left corner of the image coincides with the upper left corner of the specified cell.
Visual Basic |
Copy Code
|
---|---|
Dim wb As New C1XLBook wb.Load("C:\Project\WorkBook1.xls") |
C# |
Copy Code
|
---|---|
C1XLBook wb = new C1XLBook(); wb.Load(@"C:\Project\WorkBook1.xls"); |
Visual Basic |
Copy Code
|
---|---|
Dim img As WriteableBitmap = new WriteableBitmap(new BitmapImage(new Uri("MyImage.bmp", UriKind.Relative))); Dim sheet As XLSheet = wb.Sheets("Forecasting Report") sheet(0, 0).Value = img |
C# |
Copy Code
|
---|---|
WriteableBitmap img = new WriteableBitmap(new BitmapImage(new Uri("MyImage.bmp", UriKind.Relative))); XLSheet sheet = wb.Sheets["Forecasting Report"]; sheet[0,0].Value = img; |
Visual Basic |
Copy Code
|
---|---|
wb.Save("C:\Project\WorkBook1.xls ") System.Diagnostics.Process.Start("C:\Project\WorkBook1.xls") |
C# |
Copy Code
|
---|---|
wb.Save(@"C:\Project\WorkBook1.xls"); System.Diagnostics.Process.Start(@"C:\Project\WorkBook1.xls"); |
In this example, the image replaces the value in the first cell, and it appears at its original size in the first cell.
This second method allows you to customize the image by specifying its size, rotation angle, brightness, contrast, border, and more.
Visual Basic |
Copy Code
|
---|---|
Dim wb As New C1XLBook wb.Load("C:\Project\WorkBook1.xls") |
C# |
Copy Code
|
---|---|
C1XLBook wb = new C1XLBook(); wb.Load(@"C:\Project\WorkBook1.xls"); |
Visual Basic |
Copy Code
|
---|---|
Dim img As WriteableBitmap = new WriteableBitmap(new BitmapImage(new Uri("MyImage.bmp", UriKind.Relative))); Dim pic As New XLPictureShape(img, 1500, 1500) pic.Rotation = 30.0F pic.LineColor = Color.DarkRed pic.LineWidth = 100 ' assign the pic to the first cell of the specified sheet Dim sheet As XLSheet = wb.Sheets("Forecasting Report") sheet(0, 0).Value = pic |
C# |
Copy Code
|
---|---|
WriteableBitmap img = new WriteableBitmap(new BitmapImage(new Uri("MyImage.bmp", UriKind.Relative))); XLPictureShape pic = new XLPictureShape(img, 1500, 1500); pic.Rotation = 30.0f; pic.LineColor = Color.DarkRed; pic.LineWidth = 100; // assign the pic to the first cell of the specified sheet XLSheet sheet = wb.Sheets("Forecasting Report"); sheet[0,0].Value = pic; |
Visual Basic |
Copy Code
|
---|---|
wb.Save("C:\Project\WorkBook1.xls ") System.Diagnostics.Process.Start("C:\Project\WorkBook1.xls") |
C# |
Copy Code
|
---|---|
wb.Save(@"C:\Project\WorkBook1.xls"); System.Diagnostics.Process.Start(@"C:\Project\WorkBook1.xls"); |
In this example, the image replaces the value in the first cell, is rotated 30°, and has a dark red border. Since we have specified the horizontal and vertical position of the image, it does not appear in the first cell.
This method uses the XLPictureShape constructor to specify the image boundaries in sheet coordinates. The shape is added directly to the sheet's ShapeCollection, rather than to a specific cell.
Visual Basic |
Copy Code
|
---|---|
Dim wb As New C1XLBook wb.Load("C:\Project\WorkBook1.xls") |
C# |
Copy Code
|
---|---|
C1XLBook wb = new C1XLBook(); wb.Load(@"C:\Project\WorkBook1.xls"); |
Visual Basic |
Copy Code
|
---|---|
Dim img As WriteableBitmap = new WriteableBitmap(new BitmapImage(new Uri("MyImage.bmp", UriKind.Relative))); Dim pic As New XLPictureShape(img, 3000, 3500, 2500, 900) pic.Rotation = 30.0F pic.LineColor = Color.DarkRed pic.LineWidth = 100 ' add the pic to specified sheet's ShapeCollection Dim sheet As XLSheet = wb.Sheets("Forecasting Report") sheet.Shapes.Add(pic) |
C# |
Copy Code
|
---|---|
WriteableBitmap img = new WriteableBitmap(new BitmapImage(new Uri("MyImage.bmp", UriKind.Relative))); XLPictureShape pic = new XLPictureShape(img, 3000, 3500, 2500, 900); pic.Rotation = 30.0f; pic.LineColor = Color.DarkRed; pic.LineWidth = 100; // add the pic to specified sheet's ShapeCollection XLSheet sheet = wb.Sheets("Forecasting Report"); sheet.Shapes.Add(pic); |
Visual Basic |
Copy Code
|
---|---|
wb.Save("C:\Project\WorkBook1.xls ") System.Diagnostics.Process.Start("C:\Project\WorkBook1.xls") |
C# |
Copy Code
|
---|---|
wb.Save(@"C:\Project\WorkBook1.xls"); System.Diagnostics.Process.Start(@"C:\Project\WorkBook1.xls"); |
In this example, the shape was added to the sheet's ShapeCollection; therefore, the image does not replace the value in the first cell. Here we specified the height and width of the image, as well as the horizontal and vertical positioning.