I'm using Active Reports within my VB program to generate a report based on my data. Right now I have the report opening fine and it is allowing the user to print, copy, find, etc. I am unsure how to add the functionality to let the user choose to export the chart once the program is running.
I've been looking at many tutorials but there is always something that makes it unable to work in my program. For example this forum gives the exact code for what I want as they add an export button to the toolbar and then adds the functionality to the button. Unfortunately I am unable to access the toolbar. They access it with Me.Toolbar and I am unable to access it this way.
Another forum here doesn't add the export to the toolbar and instead inserts it directly into the code but I'm not sure what to import to allow me to do it this way as my project doesn't recognize ActiveReportsPDFExport.ARExportPDF.
UPDATE:
Found a way to export to PDF by adding to the ActiveReport in the design format a DataDynamics.ActiveReports.Export.Pdf.PdfExport and then calling from my code PdfExport1.Export(Me.Document, "D:\Kyra\HELP.pdf")
Problem:
This is called at the end of my function which opens the active report. I want the user to be able to choose to export the report and then be given the option of choosing the format and location where they want to save the report to.
Below is the code to add a PDF Export button to the ActiveReports Toolbar using VB.NET and ActiveReports 6:
Const pdfExportToolID As Long = 42
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myExportTool As DataDynamics.ActiveReports.Toolbar.Button
myExportTool = New DataDynamics.ActiveReports.Toolbar.Button()
myExportTool.ButtonStyle = DataDynamics.ActiveReports.Toolbar.ButtonStyle.Text
myExportTool.Caption = "Export to PDF"
myExportTool.Id = pdfExportToolID
Me.Viewer1.Toolbar.Tools.Add(myExportTool)
' load report:
Dim rpt As New NewActiveReport1()
Me.Viewer1.Document = rpt.Document
rpt.Run(False)
End Sub
Private Sub Viewer1_ToolClick(ByVal sender As System.Object, ByVal e As DataDynamics.ActiveReports.Toolbar.ToolClickEventArgs) Handles Viewer1.ToolClick
If (e.Tool.Id = pdfExportToolID) Then
Dim pdf As New DataDynamics.ActiveReports.Export.Pdf.PdfExport()
pdf.Export(Me.Viewer1.Document, "C:\users\scott\junk\myActiveReport.pdf")
End If
End Sub
This code works inside of a form with an ActiveReports Viewer on hte form named "Viewer1".
Hope this helps,
Scott Willeke
GrapeCity
Just follow along in the instructions here. Specifically, it's the button they add 'cmdExport' that lets the user start the export.
This code working for me, just pass it Webviewer object.
ABC.Run();
ARWebViewer.Report = ABC;
ExportToExcel(ARWebViewer); // call ExportToExcel method,
public void ExportToExcel(DataDynamics.ActiveReports.Web.WebViewer objWebviewer)
{
DataDynamics.ActiveReports.Export.Xls.XlsExport XLSexport = new DataDynamics.ActiveReports.Export.Xls.XlsExport();
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
if (XLSexport == null)
XLSexport = new DataDynamics.ActiveReports.Export.Xls.XlsExport();
XLSexport.AutoRowHeight = true;
XLSexport.MinColumnWidth = (float)0.2;
XLSexport.RemoveVerticalSpace = true;
XLSexport.UseCellMerging = true;
XLSexport.Export(objWebviewer.Report.Document, memStream);
memStream.Position = 0;
Response.ContentType = "application/Xls";
Response.AddHeader("content-disposition", "attachment; filename=" + ajDoc + ".Xls");
Response.BinaryWrite(memStream.ToArray());
Response.End();
XLSexport = null;
}
Related
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Wordprocessing
Imports DocumentFormat.OpenXml.Packaging
Public Class Add_bookmark
Const fileName As String = "F:\vb\part2 here\AddRemove.docx"
Const bookmarkName As String = "Page1"
Private Sub Add_bookmark_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using doc As WordprocessingDocument = WordprocessingDocument.Open(fileName, True)
Dim docBody As Body = doc.MainDocumentPart.Document.Body
Dim addBookmark As BookmarkStart = docBody.Descendants(Of BookmarkStart)().FirstOrDefault(Function(a) a.Name = bookmarkName)
If addBookmark Is Nothing Then
Throw New Exception(String.Format("Bookmark {0} not found", bookmarkName))
End If
'addBookmark.InsertAt(bookmarkName)
doc.MainDocumentPart.Document.Save()
End Using
End Sub
End Class
Here's my recommendation that I think will pretty much solve most Open XML SDK issue. They have both a comparison tool and a code generation tool. Use thoughts to your advantage.
Create the document you want to see in Microsoft Word. Save It.
Open the document again, add a bookmark. Save it again, but under a different name.
Open the XML SDK comparison tool and select both documents. It'll show you the differences, and also will show you the sample .NET code that can be used to create the 2 documents. In this case, you'll focus on the differences in the code.
m inexperienced at web programming, learning as I go. In my vb.net application I have created a printable web page. Now I want to make it easier for users by automatically invoking their printer. I believe that control + p will invoke a printer in most browsers, so I am trying that. (I realize it is not an elegant solution and am open to something better.) But the problem I am having is that I can evoke the printer dialog, however it prints an empty page with only the standard header and footer. I thought maybe the printer was coming up before the page was ready, so I tried putting in a time delay, but the delay seems to occur before the page renders on the page, rather than after the page is rendered and before the printer dialog shows. I am still getting empty pages. What should I do?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ScaleID = Request.QueryString.ToString
Using myConnection As New SqlConnection(connectionString)
Dim cmdScale As New SqlCommand("Select * from ScalesView where [Scale ID] = #ScaleID", myConnection)
Dim daScale As New SqlDataAdapter
Dim dsScale As New Data.DataSet
Dim dtScale As New Data.DataTable
myConnection.Open()
cmdScale.Parameters.AddWithValue("#ScaleID", ScaleID)
daScale.SelectCommand = cmdScale
cmdScale.ExecuteNonQuery()
dsScale.Clear()
daScale.Fill(dsScale, "ScalesView")
dtScale = dsScale.Tables(0)
lblName.Text = dtScale.Rows(0)("Client Name")
lblRater.Text = dtScale.Rows(0)("Rater Name")
lblBehavior.Text = dtScale.Rows(0)("Behavior Name")
lblDate.Text = dtScale.Rows(0)("Date")
lblSetting.Text = dtScale.Rows(0)("Setting Name")
lblA9.Text = dtScale.Rows(0)("Item 9")
lblD9.Text = Description(lblA9.Text)
'more code to display data here
End Using
txtTotSensory.Text = (CInt(lblA1.Text) + CInt(lblA5.Text) + CInt(lblA9.Text) + CInt(lblA13.Text)).ToString
txtTotEscape.Text = (CInt(lblA2.Text) + CInt(lblA6.Text) + CInt(lblA10.Text) + CInt(lblA14.Text)).ToString
txtTotAttention.Text = (CInt(lblA3.Text) + CInt(lblA7.Text) + CInt(lblA11.Text) + CInt(lblA15.Text)).ToString
txtTotTangible.Text = (CInt(lblA4.Text) + CInt(lblA8.Text) + CInt(lblA12.Text) + CInt(lblA16.Text)).ToString
'more data manipulation here
sortIt()
System.Threading.Thread.Sleep(10000)
SendKeys.SendWait("^(p)")
End Sub
Unless you have a very good reason for going about things this way, it sounds like you're missing a fundamental part of web development. Namely, the separation of server-side and client-side code/functionality.
If the page should be printed from the browser, that's client-side. Printing client-side is a simple JavaScript call:
window.print();
You basically can't invoke the client's printer from server-side code. (Imagine an internet where any server you visit could interact with your computer's hardware.) You can print to the server's printer (not sure why anybody would want to), but in that case you'd need something to print. And rendering the page in-memory on the server just to print it seems like overkill.
Working on a management program for basic files and text.
Now, so far the program is saving information from multiple textboxes into an .xml file correctly.
My problem is where I need to load saved files back into Textboxes.
Here is another thread I made to Microsoft explaining my issue;
Right, so the code I currently have and use;
Private Sub Objectlist1_ItemActivate(sender As Object, e As EventArgs) Handles Objectlist1.ItemActivate
Caseworker.Show()
Me.Objectlist1.MultiSelect = False
Dim selectedListViewItem As String
selectedListViewItem = Me.Objectlist1.SelectedItems.Item(0).ToString
If (IO.File.Exists(selectedListViewItem + "C:\Users\USER\Desktop\Testfolder-data")) Then
Dim document As XmlReader = New XmlTextReader(selectedListViewItem + "C:\Users\USER\Desktop\Testfolder-data")
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name = "Person") Then
Caseworker.Pholderbox.Text = document.ReadInnerXml.ToString()
End If
If (document.Name = "Driver") Then
Caseworker.Driverbox.Text = document.ReadInnerXml.ToString()
Problem here is that I want to be able to click a file in the Listview called "Objectlist1" and the program loads the xml file - Instead of directing the program to One file
As such
If (IO.File.Exists("MyXML.xml")) Then
Dim document As XmlReader = New XmlTextReader("MyXML.xml)
Apparently there is this variable out there that would be perfect for my issue, but I have looked for it for 2 working days and not been able to track it down.
If there is another stuff I need to add to make this thing work, I appreciate any help you can provide.
Am I far off here guys?
A few things:
You need the full path to the XMLFile, not just its name. You could do it like this (warning: untested):
const string basepath= #"C:\Users\USER\Desktop\Testfolder-data"
xmlpath = IO.Path.Combine(basepath, Objectlist1.SelectedItems.Item(0).Text)
If(IO.File.Exists(xmlpath))
Instead of multiple Ifs, I would recommend
switch(document.Name)
{
Case "Person":
Caseworker.Pholderbox.Text=...
break;
Case "Driver":
...
}
If you rename "Pholderbox" to "Personbox", you could spare the entire If/switch and simply do something like:
var textbox = document.name + "box";
(TextBox)Caseworker.Controls[textbox].Text=document.InnerText;
Hope this gets you going.
I want to save whatever is being typed in RichEditBox. Below is my example. I was able to successfully with TextBox by using "mytext.Text" but there is no such option that I could see of RichEditBox.
Private Async Function Button_Click(sender As Object, e As RoutedEventArgs) As Task
Dim savePicker As New FileSavePicker
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
' Dropdown of file types the user can save the file as
savePicker.FileTypeChoices.Add(".txt", New List(Of String) From {".txt"})
' Default file name if the user does not type one in or select a file to replace
savePicker.SuggestedFileName = "New Document"
Dim file As StorageFile = Await savePicker.PickSaveFileAsync
If file IsNot Nothing Then
' Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync
CachedFileManager.DeferUpdates(file)
' Write to file
Await FileIO.WriteTextAsync(file, txtfile.)
' Let Windows know that we are finished changing the file so the other app can update the remote version of the file.
' Completing updates may require windows to ask for user input
Dim status As FileUpdateStatus = Await CachedFileManager.CompleteUpdatesAsync(file)
End If
End Function
Assuming a Windows.UI.Xaml.Controls.RichEditBox, you can retrieve the text with the GetText method of the control's Document property. You can also write the document directly to a stream with the SaveToStream method of the Document property.
I Have an Image in rdlc report.
in the report i set visibility to false
I want that when I Export to PDF or EXCEL
To set the Image visibility to true.
How do I do This?
Is The a way to Catch the Export Event ?
I don`t want to create a custom 'export'.
Thanks …
The only way I found out how to do it was by creating a custom 'export' function...which really is quite simple.
Step 1: Create a parameter in your report called "ShowImage". I used the data type of String, made the prompt hidden and set a default value of "False". That way, when the report first runs in your report viewer on your page, it is not hidden.
Step 2: Change the visibility property for your image to an expression that has the following:
=CBool(Parameters!ShowImage.Value)
Step 3: Hide the Export Controls on your report viewer. Here is my example:
<rsweb:ReportViewer ID="ReportViewer1" runat="server" ShowExportControls="false" Font-Names="Verdana" Font-Size="8pt">
<LocalReport ReportPath="Report1.rdlc" >
</LocalReport>
</rsweb:ReportViewer>
Step 4: Add a button to your page and code the custom export. You will need to be sure to set the parameter you created in step 1.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create ReportViewer
Dim viewer As New Microsoft.Reporting.WebForms.ReportViewer()
Dim p(0) As Microsoft.Reporting.WebForms.ReportParameter
p(0) = New Microsoft.Reporting.WebForms.ReportParameter("ShowImage", "True")
viewer.LocalReport.ReportPath = Server.MapPath("Report1.rdlc")
viewer.LocalReport.SetParameters(p)
'Export to PDF
Dim reportContent As Byte() = viewer.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
'Return PDF
Me.Response.Clear()
Me.Response.ContentType = "application/pdf"
Me.Response.AddHeader("Content-disposition", "attachment; filename=Report.pdf")
Me.Response.BinaryWrite(reportContent)
Me.Response.End()
End Sub
That's it. May I ask, why didn't you want to create a custom export event?