NPOI를 사용하는 현재 응용 프로그램을 Azure 호스트 응용 프로그램에 서버의 xls 문서를 생성하는 데 변환하려고합니다. 나는 NPOI와 Azure에 대한 경험이 거의 없기 때문에 바로 2 명이 파업한다. 나는 Blob 컨테이너에 xls를 업로드하는 앱을 가지고 있지만 항상 비어있다 (9 바이트). 내가 이해 한 바로는 NPOI는 filestream을 사용하여 파일에 쓰기 때문에 방울 컨테이너로 쓰도록 변경했습니다. 여기Azure Blob로 변환하는 XLS 파일을 작성하는 NPOI
는 내가 관련 부분이 무엇인지 생각된다
internal void GenerateExcel(DataSet ds, int QuoteID, string ReportFileName)
{
string ExcelFileName = string.Format("{0}_{1}.xls",ReportFileName,QuoteID);
try
{
//these 2 strings will get deleted but left here for now to run side by side at the moment
string ReportDirectoryPath = HttpContext.Current.Server.MapPath(".") + "\\Reports";
if (!Directory.Exists(ReportDirectoryPath))
{
Directory.CreateDirectory(ReportDirectoryPath);
}
string ExcelReportFullPath = ReportDirectoryPath + "\\" + ExcelFileName;
if (File.Exists(ExcelReportFullPath))
{
File.Delete(ExcelReportFullPath);
}
// Create a new workbook.
var workbook = new HSSFWorkbook();
//Rest of the NPOI XLS rows cells etc. etc. all works fine when writing to disk////////////////
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("pricingappreports");
// Create the container if it doesn't already exist.
if (container.CreateIfNotExists())
{
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
}
// Retrieve reference to a blob with the same name.
CloudBlockBlob blockBlob = container.GetBlockBlobReference(ExcelFileName);
// Write the output to a file on the server
String file = ExcelReportFullPath;
using (FileStream fs = new FileStream(file, FileMode.Create))
{
workbook.Write(fs);
fs.Close();
}
// Write the output to a file on Azure Storage
String Blobfile = ExcelFileName;
using (FileStream fs = new FileStream(Blobfile, FileMode.Create))
{
workbook.Write(fs);
blockBlob.UploadFromStream(fs);
fs.Close();
}
}
내가 물방울에 업로드하고있어이와 파일이 왜 데이터가 XLS에 기록되지 않는, 존재? 도움이 될 것입니다.
업데이트 : 문제가 발견 된 것 같습니다. BLOB 저장소의 파일에 쓸 수있는 것처럼 보이지 않습니다. 이 블로그는 내 질문에 대한 답변이 많습니다. NPOI는 사용하지 않지만 개념은 같습니다. http://debugmode.net/2011/08/28/creating-and-updating-excel-file-in-windows-azure-web-role-using-open-xml-sdk/ 감사합니다.