아래 코드는 프로그래밍 방식으로 Office 2010 Excel 스프레드 시트를 XML로 저장하는 데 사용하는 코드입니다. 이 코드는 Excel 저장 옵션과 일치하는 스키마로 완벽한 XML 문서를 생성합니다. 제 질문은 interop 어셈블리를 사용하지 않고이 문제를 해결할 수있는 방법입니다. Open XML 문서를 살펴본 결과 문서를 xml로 저장할 수있는 "다른 이름으로 저장"옵션을 찾을 수 없습니다. 이것이 가능한가? C# 또는 vb.net의 도움을 주시면 감사하겠습니다..XLSX 또는 .XLSM을 XML로 변환하십시오.
Private Function ConvertExcelToXml(path As String, file As String) As Boolean
Dim returnValue as Boolean
returnValue = True
Try
Dim importfile As String = (path & file) + ".xlsm"
Dim exportfile As String = (path & file) + ".xml"
Dim app As New Application()
app.Workbooks.Open(importfile, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing)
Dim data As String = String.Empty
app.ActiveWorkbook.XmlMaps(1).ExportXml(data) 'export the excel sheet xml to the string variable
System.IO.File.Delete(exportfile) 'delete the file if it already exists
System.IO.File.WriteAllText(exportfile, data) 'write the new file
app.Workbooks.Close()
Catch ex As Exception
returnValue = false
End Try
return returnValue
End Function
덕분에, 짧은에 카오스
XML로 변환 할 때 SpreadsheetML 또는 XML Spreadheets을 언급하고 있습니까? – strongbutgood
그 형식이 무엇인지 정확하게 알지 못합니다. Excel 내에서 "다른 이름으로 저장"옵션을 사용하면 얻을 수있는 것과 일치하는 XML 파일을 얻으려고합니다. – Chaos
그래서'ActiveWorkbook.XmlMaps (1)'에 의해 검색된) xml 맵을 스프레드 시트에 어떻게 가져오고 있습니까? 처음에 일부 XML을 Excel로 가져 오거나 프로그래밍 방식으로지도를 추가하고 있습니까? – strongbutgood