Home > Net >  Turn to NPOI add excel hyperlinks
Turn to NPOI add excel hyperlinks

Time:10-04

I am in a loop created four cell, and the assignment, and then to add the same hyperlinks each cell, found that only the fourth links, effectively, and how to solve?
The code is as follows:
The namespace interfaceclass
{
Class Program
{
The static void Main (string [] args)
{
HSSFWorkbook wb=new HSSFWorkbook ();
ISheet sh=wb. CreateSheet (" zhiyuan ");
HSSFHyperlink link1=new HSSFHyperlink (HyperlinkType. File);
Link1. Address=@ "D: \ \ file \ \ automation \ \ measurement JPG";
IRow row3=sh. CreateRow (3);
int n=0;
For (n=0; n <4. N++)
{
ICell cell4=row3. CreateCell (n + 1);
Cell4. SetCellValue (n);
Cell4. The Hyperlink. Address=@ "D: \ \ file \ \ automation \ \ measurement JPG";
}

Using (FileStream STM=File. OpenWrite (@ "mylink. XLS"))
{
Wb. Write (STM);
The Console. Write (" OK ");
}
}
}
}

CodePudding user response:

  •  Tags:  
  • C #
  • Related