2014-06-13 4 views
0

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/ 감사합니다.

답변

0

피들러를 설치하고 요청 및 응답 패킷을 확인할 수 있습니까? 두 번의 쓰기 사이에 0으로 다시 탐색해야 할 수도 있습니다. 그래서 여기 올바른 코드는 blob에 스트림을 쓰려고하기 전에 아래에 추가 할 수 있습니다.

workbook.Write(fs); 
fs.Seek(0, SeekOrigin.Begin); 
blockBlob.UploadFromStream(fs); 
fs.Close(); 

은 또한 당신이 문자열 Blobfile = ExcelFileName 대신 문자열 Blobfile = ExcelReportFullPath을 사용하는 것으로 나타났습니다.

관련 문제