asp.net MVC 5 中的 powerbuilder 数据窗口报告

powerbuilder datawindow report in asp.net MVC 5

我们正在为在 PowerBuilder 12.5(Classic) + SQLServer 2014 上开发的现有应用程序 (Client/server) 开发一个网站 (ASP.Net MVC 5 with C#)。我们想使用在我们的 PB 应用程序中设计的相同报告,以节省重新设计和未来维护的时间。我们了解到可以在 C# 中使用使用 PB.Net 开发的 .Net 程序集。只是找不到合适的资源来在 MVC 网站中显示数据窗口。

试验#1: 尝试从 dw 报告中导出 html,但无法正确呈现所有字段。 dw_1.Describe("DataWindow.data.html")。更改 html table 属性(在 dw 中)除了边框和文本颜色外没有太大区别。背景颜色、有条件可见的字段、线条无法正确渲染,甚至无法关闭。也许我们做错了,有人可以启发我们。

审判#1结束。

我们正在研究的另一个选择是 运行 WCF 服务或可以从我们的网站调用的单个应用程序,以生成所需格式的报告,直到我们找到更好的解决方案允许用户下载为文件。

迫切寻求有用的资源和反馈。

我已经用你指出的两种方法取得了一些成功。

使用数据窗口 HTML 方法,我没有尝试使用像您正在尝试的那样复杂的数据对象,而是通过打开 'Generate CSS' 属性 和一些轻微摆弄各种控件的位置我能够在 HTML.

中获得数据窗口的非常接近的表示

至于下载文件的方法,我所做的是使用 powerbuilder classic 创建一个 .net 程序集,它将检索报告(数据存储)并使用 ghostscript 将其转换为 PDF。然后我在 c# web api 中使用了这个程序集,并且能够将文件下载到移动应用程序。

希望这对您有所帮助。

我有一个名为 "GuardarAExcel2()" 的函数,它使用一个名为 "d_filafichero" 的步骤数据窗口。使用此功能,您可以生成一个 excel,其视觉效果与数据窗口相同。希望对你有帮助:

我翻译了我的评论,希望你能理解。对不起我的英语。

使用示例:

GuardarAExcel2( dw_1, "c:\Report.xls")
GuardarAExcel2( dw_1, "c:\Report.html")

// This function activates CSS in the datawindow to export in Excel format, 
// doing this will maintain the visual appearance of the dw in excel.

// ***********
// TO CONSIDER
// ***********
// - If there are overlapping column or compute type controls (one above the other), 
//   the SaveAs will only record the one above it. Use the setPosition() function if possible:
//     > Example: dw.setPosition( 'campo_t', 'header', true )
// - The objects must be in the Layer: Band
// - HELP to apply special formats:
//     > http://codesnipers.com/?q=excel-compatible-html
//     > https://stigmortenmyre.no/mso/html/excel/xlconformulas.htm

String ls_GenerateCSS
String ls_Border
String ls_NoWrap
String ls_Fila
String ls_Valor
String ls_Temp
String ls_CabeceraHTML
String ls_PieHTML
String ls_NumToStr

Long i
Long ll_TRow
Long ll_Pos
Long ll_PosIni
Long ll_PosFin
Long ll_Row
Long ll_Temp

Boolean lb_Actualizar

ls_CabeceraHTML = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">'
ls_PieHTML = '</html>'
ls_NumToStr = 'x:str'

// Save current CSS datawindow format
ls_GenerateCSS = dwDatos.Describe("DataWindow.HTMLTable.GenerateCSS")
ls_Border = dwDatos.Describe("DataWindow.HTMLTable.border")
ls_NoWrap = dwDatos.Describe("DataWindow.HTMLTable.nowrap")

// Apply CSS format to datawindow
dwDatos.Modify("DataWindow.HTMLTable.GenerateCSS='1'")
dwDatos.Modify("DataWindow.HTMLTable.border='0'")
dwDatos.Modify("DataWindow.HTMLTable.nowrap='1'")

// Save the .xls file
dwDatos.SaveAs( spRuta, HTMLTable!, TRUE )

// Import the .xls file to "d_FilaFichero"
ds_datastore dsHTML
dsHTML = CREATE ds_datastore
dsHTML.DataObject = "d_FilaFichero"
dsHTML.ImportFile( Text!, spRuta )

// Process line by line for:
//   - Add in the header: <!DOCTYPE html>
//   - Replace "{;" by "{"
//   - If there is "visibility:hidden" replacing its value with spaces, excel does not support this and displays it
//          Example: Original: <TD NOWRAP CLASS=htmldw9C370 Style='visibility:hidden;'>0202002003</TD>
//                  Replaced: <TD NOWRAP CLASS=htmldw9C370 Style='visibility:hidden;'>          </TD>
//   - Number solution in parentheses, excel converts to negative number.
//   - Keep the leading zeros to the left, Excel them to convete numbers.
//   - Remove references to images that are not included:
//       Example: Original: <TD NOWRAP CLASS=htmldw152FC><IMG SRC="" border="0" CLASS=htmldw152FC  onClick="{return htmldw.itemClicked(0,-1,'compute_11',0,-1);}" ></TD>
//                Replaced: <TD NOWRAP CLASS=htmldw152FC></TD>
//   - Prevent text with / convert to date

dsHTML.InsertRow(1)
dsHTML.setItem( 1, 'fila', ls_CabeceraHTML )

dsHTML.InsertRow(0)
ll_TRow = dsHTML.RowCount()
dsHTML.setItem( ll_TRow, 'fila', ls_PieHTML )

For i = 1 to ll_TRow
    lb_Actualizar = False
    ls_Fila = dsHTML.getItemString( i, 'fila' )

    // Activation of CSS that is disabled by default
    If Pos( ls_Fila, '{;' ) > 0 Then
        ls_Fila = f_global_replace( ls_Fila, '{;', '{' )
        lb_Actualizar = True
    End If

    // Visibility
    If Pos( ls_Fila, 'visibility:hidden' ) > 0 or Pos( ls_Fila, 'visibility: hidden' ) > 0 Then
        ll_PosIni = Pos( ls_Fila, '>' )
        ll_PosFin = Pos( ls_Fila, '</' )
        If ll_PosIni > 0 and ll_PosFin > 0 Then
            ls_Valor = Mid( ls_Fila, ll_PosIni + 1, (ll_PosFin - ll_PosIni) - 1 )
            If Len( Trim( ls_Valor ) ) > 0 Then
                ls_Fila = f_global_replace( ls_Fila, ls_Valor, Space( Len( ls_Valor ) ) )
                lb_Actualizar = True
            End If
        End If
    End If

    // Number solution in parentheses, excel converts to negative number.
    ll_PosIni = Pos( ls_Fila, '>(' )
    ll_PosFin = Pos( ls_Fila, ')</' )
    If ll_PosIni > 0 and ll_PosFin > 0 Then
        ls_Valor = Mid( ls_Fila, ll_PosIni + 2, (ll_PosFin - ll_PosIni) - 2 )
        If isNumber( ls_Valor ) Then
            ls_Fila = f_global_replace( ls_Fila, ">(", ">&nbsp;(" )
            lb_Actualizar = True
        End If
    End If

    // Apply formatting to keep leading zeros
    ll_PosIni = Pos( ls_Fila, '>0' )
    ll_PosFin = Pos( ls_Fila, '</' )
    If ll_PosIni > 0 and ll_PosFin > 0 Then
        ls_Valor = Mid( ls_Fila, ll_PosIni + 1, (ll_PosFin - ll_PosIni) - 1 )
        If isNumber( ls_Valor ) Then
            If Dec( ls_Valor ) > 0 Then
                ls_Fila = f_global_replace( ls_Fila, ">0", " " + ls_NumToStr + ">0" )
                lb_Actualizar = True
            End If
        End If
    End If

    // Remove reference to images that are not included:
    ll_PosIni = Pos( ls_Fila, '<IMG SRC=""' )
    ll_PosFin = Pos( ls_Fila, '</' )
    If ll_PosIni > 0 and ll_PosFin > 0 Then
        ls_Valor = Mid( ls_Fila, ll_PosIni, (ll_PosFin - ll_PosIni) )
        If Len( Trim( ls_Valor ) ) > 0 Then
            ls_Fila = f_global_replace( ls_Fila, ls_Valor, "" )
            lb_Actualizar = True
        End If
    End If

    // Prevent text with / convert to date
    ll_PosIni = Pos( ls_Fila, '>' )
    ll_PosFin = Pos( ls_Fila, '</' )
    If ll_PosIni > 0 and ll_PosFin > 0 Then
        ls_Valor = Mid( ls_Fila, ll_PosIni + 1, (ll_PosFin - ll_PosIni) - 1 )
        If f_cuenta_char( ls_Valor, '/' ) = 1 Then
            ls_Fila = f_global_replace( ls_Fila, ">"+ls_Valor, " " + ls_NumToStr + ">"+ls_Valor )
            lb_Actualizar = True
        End If
    End If

    If lb_Actualizar Then
        dsHTML.setItem( i, 'fila', ls_Fila )
    End If
Next

// Save the "d_FilaFichero" as Txt with .xls extension
dsHTML.SaveAs( spRuta, Text!, FALSE )

// Restore the original CSS datawindow format
dwDatos.Modify("DataWindow.HTMLTable.GenerateCSS='" + ls_GenerateCSS + "'")
dwDatos.Modify("DataWindow.HTMLTable.border='" + ls_Border + "'")
dwDatos.Modify("DataWindow.HTMLTable.nowrap='" + ls_NoWrap + "'")

DESTROY dsHTML
Return 

我将从 PowerBuilder 代码生成 PDF 并在浏览器中显示它。