1
생성 된 Excel 파일에 다른 목록에 하이퍼 링크를 추가하는 데 어려움을 겪고 있습니다. 나는 이런 식으로 시도 : 개방 후EPPlus 다른 시트의 셀 하이퍼 링크
ws.Cells[1, 1].Formula="HYPERLINK(\"[#]'sheetName'!R4C1\";\"linktext\")"
ws.Cells[1, 1].Formula="HYPERLINK(\"#'sheetName'!R4C1\";\"linktext\")"
ws.Cells[1, 1].FormulaR1C1="HYPERLINK(\"[#]'sheetName'!R4C1\";\"linktext\")"
ws.Cells[1, 1].FormulaR1C1="HYPERLINK(\"#'sheetName'!R4C1\";\"linktext\")"
난 그냥 내가이 하이퍼 링크 공식을 사용하는 파일의 오류 및 모든 셀이 비어 있는지 메시지가 엑셀 365 (전체 오프라인 응용 프로그램)에서 Excel 파일 생성.
오류 메시지는 다음과 같습니다
we found a problem with some content in FILENAME do you want us to try to recover as much as we can
는 어떻게 작동하도록?
또한 동일한 수식을 수동으로 셀에 넣으면 작동합니다.
전체 코드 :
는using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExcelHyperlinkTest
{
class Program
{
static void Main(string[] args)
{
MemoryStream excelStream = new MemoryStream();
ExcelPackage excelFile = new ExcelPackage(excelStream);
ExcelWorksheet wsSrc = excelFile.Workbook.Worksheets.Add("src");
ExcelWorksheet wsTgt = excelFile.Workbook.Worksheets.Add("tgt");
wsSrc.Cells[1, 1].Formula = string.Format("HYPERLINK(\"#'{0}'!R{1}C{2}\";\"{3}\")", "tgt", 2, 5, "test"); //FormulaR1C1
excelFile.Save();
excelStream.Position = 0;
using (FileStream file = new FileStream("c:\\linkTest.xlsx", FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[excelStream.Length];
excelStream.Read(bytes, 0, (int)excelStream.Length);
file.Write(bytes, 0, bytes.Length);
excelStream.Close();
}
}
}
}