export to csv options

Stimulsoft Reports.WEB discussion
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

export to csv options

Post by brianj774 »

I am trying to figure out how to configure my export to csv.

In the first place, I need to know how to how to pre-fill the export dialog options, most notably the file encoding and the separator. I can think of about 3 ways to do this, but I can't seem to find a way in any of them (at the view, at the viewer load snapshot callback, or at the export callback-thought this fires AFTER the dialog)

In the second place, how can I override the column headers?
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

Re: export to csv options

Post by brianj774 »

in the user manual, I found section 5.8.1.1, which seems to address question #2, but I don't have a clue how to implement that in my code....
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

Re: export to csv options

Post by brianj774 »

in the 'programming manual' I found section 19.7.1.1 .... I'm confused on two counts. first, how to implement (as per my initial post), and second in regard to default values....I am skeptical that my default setting is Cyrillic, which is what comes up, but the document says it should be utf8.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: export to csv options

Post by HighAley »

Hello.
brianj774 wrote:in the user manual, I found section 5.8.1.1, which seems to address question #2, but I don't have a clue how to implement that in my code....
You should set the Tag property of the Text components on the Data Band and then the header in the csv file will be as you need.

You could set all export settings in code if you will export reports in code too.

We made a improvement and the default encoding in the Web Viewer will be UTF-8.

Thank you.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

Re: export to csv options

Post by brianj774 »

What I'm trying to do is to change the default settings for the dialog that pops up when a use selects save | Data | CSV File...

When the dialog opens, it shows page range gouping, and a settings grouping. Right now, the encoding defaults to Cyrillic for us, and we need this to be ASCII (UTF-8 may also be okay). The Separator option is set to ( ; ) semicolon, and needs to be ( , ) comma.


But, I would also accept a way to supress the ExportSettings dialog, and just manage the export entirely from code....I've found a way to do that "ShowExportDialog" and set to false, but I don't see how to then differentiate between all the different other export types. What I really want, is to just supress the CSV export dialog, and then to set the properties by hand as needed.

Please walk me thorough exactly what needs to be done to resolve this issue.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: export to csv options

Post by HighAley »

Hello.

Here is a sample code how to export report to Csv:

Code: Select all

public ActionResult ExportPdf()
{
            StiReport report = new StiReport();
            report.Load(Server.MapPath("~/Content/Report.mrt"));
            report.Render(false);

            MemoryStream stream = new MemoryStream();

            StiCsvExportSettings settings = new StiCsvExportSettings();
            settings.Separator = ",";
            settings.Encoding = Encoding.UTF8;

            StiCsvExportService service = new StiCsvExportService();
            service.ExportCsv(report, stream, settings);

            this.Response.Buffer = true;
            this.Response.ClearContent();
            this.Response.ClearHeaders();
            this.Response.ContentType = "application/pdf";
            //this.Response.AddHeader("Content-Disposition", "attachment; filename=\"report.pdf\"");
            this.Response.ContentEncoding = Encoding.UTF8;
            this.Response.AddHeader("Content-Length", stream.Length.ToString());
            this.Response.BinaryWrite(stream.ToArray());
            this.Response.End();
}
The sample of using Tag property is in the attached report template. Please, look at the Tag property of the text components on the Band.
SimpleList.mrt
(24.23 KiB) Downloaded 500 times
Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: export to csv options

Post by HighAley »

Hello.
brianj774 wrote:What I'm trying to do is to change the default settings for the dialog that pops up when a use selects save | Data | CSV File...

When the dialog opens, it shows page range gouping, and a settings grouping. Right now, the encoding defaults to Cyrillic for us, and we need this to be ASCII (UTF-8 may also be okay). The Separator option is set to ( ; ) semicolon, and needs to be ( , ) comma.


But, I would also accept a way to supress the ExportSettings dialog, and just manage the export entirely from code....I've found a way to do that "ShowExportDialog" and set to false, but I don't see how to then differentiate between all the different other export types. What I really want, is to just supress the CSV export dialog, and then to set the properties by hand as needed.

Please walk me thorough exactly what needs to be done to resolve this issue.
We need some time to made an improvement of your issue. There is no solution now but it will be available in one of our next builds.

Thank you.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

Re: export to csv options

Post by brianj774 »

In case anybody in interested, here's the solution I came up with...its far from perfect, but gets me where I need to go (for now). Future features from Stimulsoft will be most welcome :D.
====================

Code: Select all

		public FileResult ExportReport() {
			// Return the exported report file
			var report = StiMvcViewer.GetReportObject(httpCtx);
			var format = httpCtx.Request.Form["exportformat"];
			var filename = String.Format("{0:s}_report.", DateTime.Now);
			var contentType = "";
			

			if (format == "Csv")
			{
				contentType = "text/csv";
				filename += "csv";
				var service = new StiCsvExportService();
				var settings = new StiCsvExportSettings();
				settings.Encoding = System.Text.Encoding.UTF8;
				settings.Separator = ",";


				var stream = new MemoryStream();
				service.ExportCsv(report, stream, settings);

				return File(stream.ToArray(), contentType, filename);
			}

			if (format == "Excel") {
				contentType = "application/vnd.ms-excel";
				filename += "xls";
				var service = new StiExcelExportService();
				var settings = new StiExcelExportSettings();
				settings.ExportDataOnly = true;

				var stream = new MemoryStream();
				service.ExportExcel(report, stream, settings);

				return File(stream.ToArray(), contentType, filename);
			} 

			return StiMvcViewer.ExportReportResult(httpCtx);
		}

HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: export to csv options

Post by HighAley »

Hello.

In this code you overwrite the user settings. No matter what user will set.

Thank you.
brianj774
Posts: 177
Joined: Tue Jan 11, 2011 7:15 am
Location: Minnesota

Re: export to csv options

Post by brianj774 »

in my solution, the users settings will (ultimately) come from a preferences dialog in a different part of the system..

But, in a previous post in this thread, I'd said that I will be setting "ShowExportDialog" to false, so, there will be no user settings for the user to set.

however, your concern is right on, which is why I was asking for a way to be able to 'preset' the user settings dialog, instead of this. This solution is a functional workaround until that other feature becomes available.
Post Reply