itsource

로컬 파일을 생성하지 않고 OpenXML을 사용하여 Excel 파일을 생성하는 방법은 무엇입니까?

mycopycode 2023. 4. 17. 21:47
반응형

로컬 파일을 생성하지 않고 OpenXML을 사용하여 Excel 파일을 생성하는 방법은 무엇입니까?

로컬 파일을 생성하지 않고 OpenXML SDK를 사용하여 Excel 문서를 만들고 편집할 수 있습니까?

설명서에 따르면Create의 메서드 요구filepath파일 로컬복사를 만듭니다.

SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);

MSDN 기사 https://msdn.microsoft.com/en-us/library/office/ff478153.aspx 를 참조하고 있습니다.

제가 요구하는 것은 파일을 만드는 것이며, 버튼을 클릭하면 브라우저에서 다운로드가 됩니다.

제안해 주실 수 있나요?

그 과부하를 이용하려면Streama를 건네주다MemoryStream:

MemoryStream memoryStream = new MemoryStream();
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook);

//add the excel contents...

//reset the position to the start of the stream
memoryStream.Seek(0, SeekOrigin.Begin);

return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

이 StackOverflow 질문에 따르면 스트림을 폐기할 필요는 없습니다.이것은, 에 의해서 행해집니다.FileStreamResult학급.

이것을 찾는데 너무 많은 시간을 소비했기 때문에 다른 답변을 추가합니다.스프레드시트 문서를 스트림에 저장하는 또 다른 방법은 스프레드시트 문서를 호출하는 것입니다.클론(Stream s)

저장하지 않을 파일 또는 스트림에서 문서를 작성한 경우에도 스트림에 저장할 수 있는 장점이 있습니다.

언급URL : https://stackoverflow.com/questions/29887503/how-to-create-excel-file-using-openxml-without-creating-a-local-file

반응형