Forum Discussion
9 Replies
- HectorNew Contributor II
Go to security, select your user. Go to preferences and change the Grid Rows Per Page.
HC
- syedfasiullahNew Contributor II
Thanks Hector - what if I have more than 1000 rows, then how would I do it? I tried that option, it has maximum of only 1000 rows.
Thanks
- FredLucas
OneStream Employee
Hi syedfasiullah,
In that case you might want to export the content of the table to .csv via a business rule.
You could do this by getting the data you want to export into a data table object like this:
Dim dtResult As DataTable Using dbConnApp As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si) Dim strSQL As New Text.StringBuilder strSQL.AppendLine("Select * from TableToExport") dtResult = BRApi.Database.ExecuteSqlUsingReader(dbConnApp, strSQL.ToString, False) End UsingAnd then use the DataTableToFile function that I've shared on this post:
- Goodwin1New Contributor
If you are just trying to get the contents out of the OS table into a csv file, you can create a SQL data adapter and hook it to a grid view component and dashboard. After that, all you have to do is right click on the grid view and export to a csv.
- AlvaroNew Contributor III
Hi!
In a grid view, you can't download millions of records; each page has a maximum of 1000 records. This method wouldn't be possible for tables with millions of records.
- Goodwin1New Contributor
I agree that, if the tables happen to have millions of rows, then grid view probably isn't a viable option. Having said that, I have exported files from the grid view that was far in excess of 1000 records. In fact, I just did one with a tad under 40,000 rows and it worked fine.
- AlvaroNew Contributor III
Hello , this code was useful for me and get the same purpose:
Namespace OneStream.BusinessRule.Extender.Test_ExportTabletoCSVPublic Class MainClassPublic Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As ObjectDim extender As New MainClass()TryDim strSQL As String = "SELECT * FROM TableName"Dim dt As DataTableUsing dbConnApp As DBConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)dt = BRApi.Database.ExecuteSqlUsingReader(dbConnApp, strSQL, True)End UsingIf dt Is Nothing OrElse dt.Rows.Count = 0 ThenBRApi.ErrorLog.LogMessage(si, "⚠️ La consulta no devolvió filas.")Return "No hay datos para exportar."End IfDim fileName As String = "ExportTablaTest.csv"Dim filePathOS As String = $"Documents\Public\{fileName}"BRApi.ErrorLog.LogMessage(si, "[DEBUG] Generando CSV...")Dim csvContent As String = DataTableToCSV(dt, ";")Dim utf8WithBom As New System.Text.UTF8Encoding(True)Dim bytes() As Byte = utf8WithBom.GetBytes(csvContent)BRApi.ErrorLog.LogMessage(si, $"[DEBUG] CSV generado. Bytes: {bytes.Length}")Dim fileInfo As New XFFileInfo(fileSystemLocation.ApplicationDatabase, filePathOS)Dim xfFile As New XFFile(fileInfo, String.Empty, bytes)BRApi.ErrorLog.LogMessage(si, "[DEBUG] Intentando guardar archivo...")BRApi.FileSystem.InsertOrUpdateFile(si, xfFile)Return $"✅ Exportación completada: {filePathOS}"Catch ex As ExceptionBRApi.ErrorLog.LogMessage(si, "❌ Error al guardar CSV: " & ex.ToString())Return $"❌ Error: {ex.Message}"End TryEnd Function' Convierte el DataTable a texto CSVPublic Function DataTableToCSV(dt As DataTable, Optional separator As String = ";") As StringDim sb As New StringBuilder()' --- Cabecera ---For i As Integer = 0 To dt.Columns.Count - 1Dim colName As String = EscapeCsvValue(dt.Columns(i).ColumnName)sb.Append(colName)If i < dt.Columns.Count - 1 Then sb.Append(separator)Nextsb.AppendLine()' --- Filas ---For Each row As DataRow In dt.RowsFor i As Integer = 0 To dt.Columns.Count - 1Dim value As String = EscapeCsvValue(row(i).ToString())sb.Append(value)If i < dt.Columns.Count - 1 Then sb.Append(separator)Nextsb.AppendLine()NextReturn sb.ToString()End Function' --- Función auxiliar que asegura formato CSV válido ---Private Function EscapeCsvValue(value As String) As StringIf value Is Nothing Then value = ""' Si contiene separadores, comillas, saltos de línea o guiones, se encierra entre comillasDim needsQuotes As Boolean = value.Contains("""") OrElsevalue.Contains(";") OrElsevalue.Contains(",") OrElsevalue.Contains(vbCr) OrElsevalue.Contains(vbLf) OrElsevalue.Contains("-")' Escapa las comillas internas duplicándolas (" → "")value = value.Replace("""", """""")If needsQuotes ThenReturn $"""{value}"""ElseReturn valueEnd IfEnd FunctionEnd ClassEnd Namespace
Related Content
- 7 months ago
- 3 years ago
- 3 months ago