2016-03-24 2 views
0

Ich versuche, ein Bild in ein Excel-Blatt mit Hilfe der Bytescout-Bibliothek einzufügen. Aber es passiert nicht.Wie setze ich eine Zelle in Excel mit einem Bild in C#?

Meine Forderung ist zu erstellen Sie eine neue Excel- und dann Einsatzdaten einschließlich Bilder Datei. Ich möchte nur irgendeine Art von Ansatz, wie jede Bibliothek, nicht nur Bytescout.

Könnte mir jemand helfen?

+1

Siehe [this] (http://www.gemboxsoftware.com/SampleExplorer/Spreadsheet/BasicFeatures/Images), das Beispiel zeigt, wie man eine neue Excel-Datei erstellt und ihr Bilder mit [GemBox.Spreadsheet] (http : //www.gemboxsoftware.com/spreadsheet/overview) Bibliothek. –

+0

Vielen Dank für Ihre Antwort. Ich werde es mir ansehen. –

Antwort

1

Sie hinzufügen können Bilder und Grafiken in XLX/XLSX-Tabellen generiert mit ByteScout Spreadsheet SDK mit dem folgenden Code:

in Visual Basic .NET:

Imports System.Collections.Generic 
Imports System.Diagnostics 
Imports System.IO 
Imports System.Text 
Imports Bytescout.Spreadsheet 

Class Program 
    Friend Shared Sub Main(args As String()) 
     ' Create spreadsheet 
     Dim doc As New Spreadsheet() 
     ' Add worksheet 
     Dim worksheet As Worksheet = doc.Worksheets.Add() 

     ' Put an image on the worksheet with 10 pixel margin from the top-left corner of the worksheet 
     worksheet.Pictures.Add("image1.jpg", 10, 10) 
     ' Put second image to 200 pixel offset and resize it to 250x200 px 
     worksheet.Pictures.Add("image2.jpg", 200, 200, 250, 200) 

     ' Save document 
     doc.SaveAs("output.xls") 

     ' Close spreadsheet 
     doc.Close() 

     ' Open generated XLS document in default application 
     Process.Start("output.xls") 

     doc.Dispose() 
    End Sub 
End Class 

Und in C#:

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.IO; 
using System.Text; 
using Bytescout.Spreadsheet; 
using Bytescout.Spreadsheet.MSODrawing; 

namespace AddImages 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      // Create spreadsheet 
      Spreadsheet doc = new Spreadsheet(); 
      // Add worksheet 
      Worksheet worksheet = doc.Worksheets.Add(); 

      // Put an image to "C3" cell 
      PictureShape shape = worksheet.Pictures.Add(2, 2, "image1.jpg"); 

      // Make the picture "floating". It will be not moved if you move or resize the "C3" cell 
      shape.PlacementType = Placement.FreeFloating; 

      // Make the picture brighter 
      shape.Brightness = 0.8f; 

      // Put second image to "K11" cell 
      shape = worksheet.Pictures.Add(10, 10, "image2.jpg"); 

      // Make the picture bound to the cell. It will be moved along with the "K11" cell 
      shape.PlacementType = Placement.Move; 

      // Crop 10% from left and right side of the image 
      shape.CropFromLeft = 0.1f; 
      shape.CropFromRight = 0.1f; 

      // Save document 
      doc.SaveAs("output.xls"); 

      // Close spreadsheet 
      doc.Close(); 

      // Open generated XLS document in default application 
      Process.Start("output.xls"); 

      doc.Dispose(); 
     } 
    } 
} 

Für weitere Codebeispiele durchsuchen Sie Spreadsheet SDK online documentation - * Advanced Examples .. * Abschnitt für weitere Quellcode-Beispiele, die Funktionen wie das Hinzufügen von Bildern zu neuen und vorhandenen Bildern abdecken Tabellen, Diagramme und andere hinzufügen.

Verwandte Themen