Lägg till ikoner i arbetsbladet
Contents
[
Hide
]
Lägg till ikoner i arbetsbladet i Aspose.Cells
Om du behöver användaAspose.Cells för att lägga till “ikoner” i en Excel-fil, då kan detta dokument ge dig lite hjälp.
Excel-gränssnittet som motsvarar operationen för infogning av ikonen är som följer:
- Välj positionen för ikonen som ska infogas i kalkylbladet
- Vänster klickFöra in->Ikoner
- I fönstret som öppnas väljer du ikonen i den röda rektangeln i figuren ovan
- Vänster klickFöra in, kommer den att infogas i Excel-filen.
Effekten är som följer:
Här har vi förberett ossExempelkod för att hjälpa dig att infoga ikoner medAspose.Cells .Det finns också en nödvändigexempelfil och en ikonresursfil .Vi använde Excel-gränssnittet för att infoga en ikon med samma visningseffekt somresursfil iexempelfil.
C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Read icon resource file data | |
string fileName = "icon.svg"; | |
FileStream fsSource = File.OpenRead(fileName); | |
byte[] bytes = new byte[fsSource.Length]; | |
int numBytesToRead = (int)fsSource.Length; | |
int numBytesRead = 0; | |
while (numBytesToRead > 0) | |
{ | |
// Read may return anything from 0 to numBytesToRead. | |
int n = fsSource.Read(bytes, numBytesRead, numBytesToRead); | |
// Break when the end of the file is reached. | |
if (n == 0) | |
break; | |
numBytesRead += n; | |
numBytesToRead -= n; | |
} | |
fsSource.Close(); | |
// Create workbook from sample file | |
Workbook workbook = new Workbook("sample.xlsx"); | |
// Access first worksheet from the collection | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Add the icon to the worksheet | |
sheet.Shapes.AddIcons(3, 0, 7, 0, 100, 100, bytes, null); | |
//Set a prompt message | |
Cell c = sheet.Cells[8,7]; | |
c.Value = "Insert via Aspose.Cells"; | |
Style s = c.GetStyle(); | |
s.Font.Color = Color.Blue; | |
c.SetStyle(s); | |
//Save.You can check your icon in this way. | |
workbook.Save("sample2.xlsx", SaveFormat.Xlsx); |
När du kör ovanstående kod i ditt projekt får du följande resultat: