Agregar iconos a la hoja de cálculo

Agregar iconos a la hoja de cálculo en Aspose.Cells

Si necesita usar Aspose.Cells para agregar ‘iconos’ en un archivo de Excel, este documento puede ofrecerle ayuda.

La interfaz de Excel correspondiente a la operación de insertar icono es la siguiente:

  • Seleccione la posición del icono a insertar en la hoja de cálculo
  • Haga clic izquierdo Insertar->Iconos
  • En la ventana que se abre, seleccione el icono en el rectángulo rojo en la figura anterior
  • Haga clic izquierdo Insertar, se insertará en el archivo de Excel.

El efecto es el siguiente:

Aquí, hemos preparado código de muestra para ayudarlo a insertar iconos usando Aspose.Cells. También hay un archivo de muestra necesario y un archivo de recursos de iconos (icon.zip). Usamos la interfaz de Excel para insertar un icono con el mismo efecto de visualización que el archivo de recursos en el archivo de muestra.

C#

// 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);

Cuando ejecute el código anterior en su proyecto, obtendrá los siguientes resultados: