> ' Export a dataset into an Excel spreadsheet > ' expO1 DataSet > ' expC1 Full path of the file to save > Public Function ExportToExcel(ByVal toDataSet As DataSet, ByVal tcFile As String) As Boolean > Dim lcFile As String = oApp.GenerateFileName() > Dim lcXml As String = "" > Dim lcXsl As String = "" > Dim loFileStream As FileStream > Dim loXml As Framework.XML > Dim loXslCompiledTransform As Xsl.XslCompiledTransform = New Xsl.XslCompiledTransform > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > loXml = New Framework.XML(oApp) > Else > loXml = New Framework.XML(oProcess) > End If > > ' Load the Xml > If Not loXml.LoadXml(oApp.DataSetToXml(toDataSet)) Then > Return False > End If > > ' Normalize the Xml > If Not loXml.Normalize() Then > Return False > End If > > ' Get the Xml > lcXml = loXml.cXml > > ' Add the French header because by default there isn't so we cover it all > lcXml = loXml.AddHeaderForFrenchCharacter() + lcXml > > ' Save in a Xml file > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > If Not oApp.CreateFile(lcXml, oApp.cHttpFat + "Temp\" + lcFile + ".xml") Then > Return False > End If > Else > If Not oProcess.CreateFile(lcXml, oApp.cHttpFat + "Temp\" + lcFile + ".xml") Then > Return False > End If > End If > > ' Generate a Xsl string based on the dataset > lcXsl = GetXsl() > > ' Save the Xsl file > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > If Not oApp.CreateFile(lcXsl, oApp.cHttpFat + "Temp\" + lcFile + ".xsl") Then > Return False > End If > Else > If Not oProcess.CreateFile(lcXsl, oApp.cHttpFat + "Temp\" + lcFile + ".xsl") Then > Return False > End If > End If > > ' Load the Xsl in memory > loXslCompiledTransform.Load(oApp.cHttpFat + "Temp\" + lcFile + ".xsl") > > ' Load the target file in memory > loFileStream = New FileStream(tcFile, FileMode.Create) > > ' Do the transformation > Try > loXslCompiledTransform.Transform(New XPath.XPathDocument(oApp.cHttpFat + "Temp\" + lcFile + ".xml"), Nothing, loFileStream) > Catch loError As Exception > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > oApp.ErrorSetup(loError) > Else > oProcess.ErrorSetup(loError) > End If > > Return False > End Try > > ' We can now remove the temporary files > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > oApp.DeleteFile(oApp.cHttpFat + "Temp\" + lcFile + ".xml") > oApp.DeleteFile(oApp.cHttpFat + "Temp\" + lcFile + ".xsl") > Else > oProcess.DeleteFile(oApp.cHttpFat + "Temp\" + lcFile + ".xml") > oProcess.DeleteFile(oApp.cHttpFat + "Temp\" + lcFile + ".xsl") > End If > > Return True > End Function >