I have a reportviewer and have enabled print button but not enabled toolbar.When user press enter reportviewer should start printing.It should not show even printdialog also.What code should i write in KeyPres event ?
This is what worked for me when I wanted to programmatically print from ReportViewer.
You'll want to set the PrintController to StandardPrintController to suppress the print dialog, e.g.
printDoc.PrintController = new System.Drawing.Printing.StandardPrintController();
Here is my code for manual printing in Report Viewer. It's in VB.NET though.
It works by handling the Print Event of your PrintDocument object.
Dim m_pageSettings As PageSettings 'Stores page settings for printout
Dim m_currentPage As Integer 'Used for index of pages
Private m_pages As New List(Of Stream)() 'Stores a stream for each pages
'Event fires when printDocument starts printing - reset page index to zero
Private Sub PrintDocument1_BeginPrint(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
m_currentPage = 0
End Sub
'Function that prints all the pages included in the report
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim pageToPrint As Stream = m_pages(m_currentPage)
pageToPrint.Position = 0
Dim pageMetaFile As Metafile = New Metafile(pageToPrint) 'create an image(metafile) of the report page
Using (pageMetaFile)
'Create a rectangle the size of our report - include margins
' Dim adjustedRect As Rectangle = New Rectangle( _
' e.PageBounds.Left - CType(e.PageSettings.HardMarginX, Integer), _
' e.PageBounds.Top - CType(e.PageSettings.HardMarginY, Integer), _
' e.PageBounds.Width, _
' e.PageBounds.Height)
Dim adjustedRect As Rectangle = New Rectangle( _
e.PageBounds.Left, _
e.PageBounds.Top, _
e.PageBounds.Width, _
e.PageBounds.Height)
e.Graphics.FillRectangle(Brushes.White, adjustedRect) 'Fill rectangle with WHITE background
e.Graphics.DrawImage(pageMetaFile, adjustedRect) 'Draw report in rectangle - this will be printed
m_currentPage = m_currentPage + 1
e.HasMorePages = m_currentPage < m_pages.Count 'If more pages are left - keep processing
End Using
End Sub
'Event fires when PrintDocument queries for PageSettings. Return a copy of m_pagesettings.
Private Sub PrintDocument1_QueryPageSettings(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
e.PageSettings = CType(m_pageSettings.Clone, PageSettings)
End Sub
'Render the report in a EMF - This function creates metafiles(images) of each page in the report
Private Sub RenderAllLocalReportPages(ByVal localReport As LocalReport)
Dim deviceInfo As String = CreateEMFDeviceInfo() 'Enhanced MetaFile
Dim warnings As Warning() = Nothing
localReport.Render("IMAGE", deviceInfo, AddressOf LocalReportCreateStreamCallback, warnings)
End Sub
'Callback function used with RenderAllLocalReportPages
Private Function LocalReportCreateStreamCallback(ByVal name As String, ByVal extension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
Dim stream As New MemoryStream()
m_pages.Add(stream)
Return stream
End Function
Private Function CreateEMFDeviceInfo() As String
Dim paperSize As PaperSize = m_pageSettings.PaperSize
Dim margins As Margins = m_pageSettings.Margins
'The device info string defines the page range to print as well as the size of the page.
'A start and end page of 0 means generate all pages.
Return String.Format(CultureInfo.InvariantCulture, "<DeviceInfo><OutputFormat>emf</OutputFormat><StartPage>0</StartPage><EndPage>0</EndPage><MarginTop>{0}</MarginTop><MarginLeft>{1}</MarginLeft><MarginRight>{2}</MarginRight><MarginBottom>{3}</MarginBottom><PageHeight>{4}</PageHeight><PageWidth>{5}</PageWidth></DeviceInfo>", ToInches(margins.Top), ToInches(margins.Left), ToInches(margins.Right), ToInches(margins.Bottom), ToInches(paperSize.Height), ToInches(paperSize.Width))
End Function
'Convert report printing size to inches
Private Shared Function ToInches(ByVal hundrethsOfInch As Integer) As String
Dim inches As Double = hundrethsOfInch / 100.0R
Return inches.ToString(CultureInfo.InvariantCulture) & "in"
End Function
I am using custom reporting for my project. Custom means the report that is built using e.Graphics.DrawString type code.
So I made All the report(coding) in the default printing event of PrintDocument
Here is the of the PrintDocument Tool. Drag and Drop it on your screen and then double click on it to create the event handler.
The code behind event handler of PrintDocoument is:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Image image = Properties.Resources.New_Header;
Font font = new Font("Arial", 7, FontStyle.Bold);
Font font2 = new Font("Arial", 7, FontStyle.Regular);
float fontHeight = font2.GetHeight();
e.Graphics.DrawImage(image, 20, 5, 260, 130);
e.Graphics.DrawString("Date:" + DateTime.Now.ToShortDateString(), new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(20, 160));
e.Graphics.DrawString("Invoice#: "+InvoiceNoTextBox.Text, new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(160, 160));
e.Graphics.DrawString("Client Name: " + ClientNameTextBox.Text.Trim(), new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(20, 180));
e.Graphics.DrawString("______________________________",
new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(20, 190));
e.Graphics.DrawString("Product", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(23, 220));
e.Graphics.DrawString("U/Price", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(170, 220));
e.Graphics.DrawString("Qty", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(210, 220));
e.Graphics.DrawString("Total", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(240, 220));
e.Graphics.DrawString("______________________________",
new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(20, 220));
int CurrentX = 25;
int CurrentY = 230;
int offset = 20;
foreach (var i in shoppingCart)
{
e.Graphics.DrawString(i.ItemName, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(CurrentX, CurrentY+offset));
e.Graphics.DrawString(i.UnitPrice.ToString(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + offset));
e.Graphics.DrawString(i.Quantity.ToString(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(215, CurrentY + offset));
e.Graphics.DrawString(i.TotalPrice.ToString(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(240, CurrentY + offset));
offset = offset + (int)fontHeight + 5;
}
CurrentY = CurrentY+offset;
e.Graphics.DrawString("______________________________",
new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY-5));
e.Graphics.DrawString("Total Amt: Rs." + TotalAmountTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 35));
e.Graphics.DrawString("Discount%: " + DiscountTextBox.Text.Trim()+"%", new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 50));
e.Graphics.DrawString("Discount: Rs." + JustDiscountTextBox.Text.Trim(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 65));
e.Graphics.DrawString("Grand Total: Rs." + TotalToPayTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 80));
e.Graphics.DrawString("Advance: Rs." + AdvancePaymentTextBox.Text.Trim(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 95));
e.Graphics.DrawString("Cash: Rs." + givenCash.Text.Trim(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 95));
e.Graphics.DrawString("Pending: Rs." + PendingPaymentTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 110));
e.Graphics.DrawString("Return: Rs." + ReturnTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 110));
e.Graphics.DrawString("Software Provided By Muhammad Abbas", new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 125));
e.Graphics.DrawString("Mob:0304-9550308", new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 140));
}
private void PrintPreviewButton_Click(object sender, EventArgs e)
{
try
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
And Finally the Answer of you Question. Use this in your Form KeyDown event.
private void Form_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
printDocument1.Print();
}
}
It will Directly print your receipt from your Printer.
Related
I want to write an algorithm that converts integer numbers to roman numbers and supports any positive number in dart.
I can do this in Java using String builder and i tried to do it in dart but i failed.
so please if anyone could help me, that would be very much appreciated!
here is the java algorithm, maybe it would help:
public static int[] arabianRomanNumbers = new int[]{
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
};
public static String[] romanNumbers = new String[]{
"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"
};
public String intToRoman(int num) {
if (num < 0) return "";
else if (num == 0) return "nulla";
StringBuilder builder = new StringBuilder();
for (int a = 0; a < arabianRomanNumbers.length; a++) {
int times = num / arabianRomanNumbers[a]; // equals 1 only when arabianRomanNumbers[a] = num
// executes n times where n is the number of times you have to add
// the current roman number value to reach current num.
builder.append(romanNumbers[a].repeat(times));
num -= times * arabianRomanNumbers[a]; // subtract previous roman number value from num
}
return builder.toString();
}
StringBuilder is called StringBuffer in Dart and does nearly the same but with a little different interface which you can read more about in the API documentation:
https://api.dart.dev/stable/2.7.1/dart-core/StringBuffer-class.html
With this knowledge, I have converted your Java code into Dart:
const List<int> arabianRomanNumbers = [
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
];
const List<String> romanNumbers = [
"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"
];
String intToRoman(int input) {
var num = input;
if (num < 0) {
return "";
}
else if (num == 0) {
return "nulla";
}
final builder = StringBuffer();
for (var a = 0; a < arabianRomanNumbers.length; a++) {
final times = (num / arabianRomanNumbers[a]).truncate(); // equals 1 only when arabianRomanNumbers[a] = num
// executes n times where n is the number of times you have to add
// the current roman number value to reach current num.
builder.write(romanNumbers[a] * times);
num -= times * arabianRomanNumbers[a]; // subtract previous roman number value from num
}
return builder.toString();
}
void main() {
for (var i = 0; i <= 1000; i++) {
print('$i => ${intToRoman(i)}');
}
}
I'm trying to parse int and double values which I receive from a bluetooth device using this lib: https://github.com/Polidea/FlutterBleLib
I receive the following Uint8List data: 31,212,243,57,0,224,7,1,6,5,9,21,0,1,0,0,0,91,228
I found some help here: How do I read a 16-bit int from a Uint8List in Dart?
On Android I have done some similar work, but the library there had so called Value Interpreter which I only passed the data and received back float/int.
Example code from Android:
int offset = 0;
final double spOPercentage = ValueInterpreter.getFloatValue(value, FORMAT_SFLOAT, offset);
Where value is a byte array
Another example from android code, this code if from the library:
public static Float getFloatValue(#NonNull byte[] value, int formatType, #IntRange(from = 0L) int offset) {
if (offset + getTypeLen(formatType) > value.length) {
return null;
} else {
switch(formatType) {
case 50:
return bytesToFloat(value[offset], value[offset + 1]);
case 52:
return bytesToFloat(value[offset], value[offset + 1], value[offset + 2], value[offset + 3]);
default:
return null;
}
}
}
private static float bytesToFloat(byte b0, byte b1) {
int mantissa = unsignedToSigned(unsignedByteToInt(b0) + ((unsignedByteToInt(b1) & 15) << 8), 12);
int exponent = unsignedToSigned(unsignedByteToInt(b1) >> 4, 4);
return (float)((double)mantissa * Math.pow(10.0D, (double)exponent));
}
private static float bytesToFloat(byte b0, byte b1, byte b2, byte b3) {
int mantissa = unsignedToSigned(unsignedByteToInt(b0) + (unsignedByteToInt(b1) << 8) +
(unsignedByteToInt(b2) << 16), 24);
return (float)((double)mantissa * Math.pow(10.0D, (double)b3));
}
private static int unsignedByteToInt(byte b) {
return b & 255;
}
In flutter/dart I want to write my own value interpreter.
The starting example code is:
int offset = 1;
ByteData bytes = list.buffer.asByteData();
bytes.getUint16(offset);
I don't understand how data is manipulated here in dart to get a int value from different position from data list. I need some explanation how to do this, would be great if anyone can give some teaching about this.
Having the following:
values [31, 212, 243, 57, 0, 224, 7, 1, 6, 5, 9, 21, 0, 1, 0, 0, 0, 91, 228];
index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
When you make:
values.list.buffer.asByteData().getUint16(0);
you interpret [31, 212] as a single unsigned int of two bytes length.
If you want to get a Uint16 from bytes 9 and 10 [5, 9], you'd call:
values.list.buffer.asByteData().getUint16(9);
Regarding your comment (Parse int and float values from Uint8List Dart):
I have this Uint8List and the values are: 31, 212, 243, 57, 0, 224, 7, 1, 6, 5, 9, 21, 0, 1, 0, 0, 0, 91, 228 I use the code below ByteData bytes = list.buffer.asByteData(); int offset = 1; double value = bytes.getFloat32(offset); and value that I expected should be something between 50 and 150 More info on what I am doing can be found here: bluetooth.com/wp-content/uploads/Sitecore-Media-Library/Gatt/… name="SpO2PR-Spot-Check - SpO2"
This property is of type SFLOAT, which according to https://www.bluetooth.com/specifications/assigned-numbers/format-types/ looks like this:
0x16 SFLOAT IEEE-11073 16-bit SFLOAT
As Dart does not seem to have an easy way to get that format, you might have to create a parser yourself using raw bytes.
These might be helpful:
https://stackoverflow.com/a/51391743/6413439
https://stackoverflow.com/a/16474957/6413439
Here is something that I used to convert sfloat to double in dart for our flutter app.
double sfloat2double(ieee11073) {
var reservedValues = {
0x07FE: 'PositiveInfinity',
0x07FF: 'NaN',
0x0800: 'NaN',
0x0801: 'NaN',
0x0802: 'NegativeInfinity'
};
var mantissa = ieee11073 & 0x0FFF;
if (reservedValues.containsKey(mantissa)){
return 0.0; // basically error
}
if ((ieee11073 & 0x0800) != 0){
mantissa = -((ieee11073 & 0x0FFF) + 1 );
}else{
mantissa = (ieee11073 & 0x0FFF);
}
var exponent = ieee11073 >> 12;
if (((ieee11073 >> 12) & 0x8) != 0){
exponent = -((~(ieee11073 >> 12) & 0x0F) + 1 );
}else{
exponent = ((ieee11073 >> 12) & 0x0F);
}
var magnitude = pow(10, exponent);
return (mantissa * magnitude);
}
I am having an assertion error when using the Core.inRange function, actually any Core. function. I have followed all solutions in the answers from similar questions. Other solutions have been to check the number of channels, check if the image is empty and verify installation. I am using Android Studio 2.2 on Mac. Phones tested were ZTE Speed KitKat and Moto g3 Marshmallow.
My goal is to get the red and blue from an image -> determine if a Red light is On or a Blue one is on. The code gets the image from a Vuforia Frame, converts it to a bitmap and then try to use OpenCV to manipulate the image. This was working on previous code before we had to implement Vuforia as part of the core.
This is the main section of the code, the Imgproc.cvtColor function works fine, its the very last one Core.inRange
Mat mat1 = new Mat(640,480, CvType.CV_8UC4);
Mat mat2 = new Mat(640,480, CvType.CV_8UC4);
Mat mat3 = new Mat(640,480, CvType.CV_8UC4);
.......
Log.d("OPENCV","Height " + rgb.getHeight() + " Width " + rgb.getWidth());
Bitmap bm = Bitmap.createBitmap(rgb.getWidth(), rgb.getHeight(), Bitmap.Config.RGB_565);
bm.copyPixelsFromBuffer(rgb.getPixels());
//Mat tmp = OCVUtils.bitmapToMat(bm, CvType.CV_8UC4);
Mat tmp = new Mat(rgb.getWidth(), rgb.getHeight(), CvType.CV_8UC4);
Utils.bitmapToMat(bm, tmp);
SaveImage(tmp, "-raw");
fileLogger.writeEvent("process()","Saved original file ");
Log.d("OPENCV","CV_8UC4 Height " + tmp.height() + " Width " + tmp.width());
Log.d("OPENCV","Channels " + tmp.channels());
tmp.convertTo(mat1, CvType.CV_8UC4);
Size size = new Size(640,480);//the dst image size,e.g.100x100
resize(mat1,mat1,size);//resize image
SaveImage(mat1, "-convertcv_8uc4");
Log.d("OPENCV","CV_8UC4 Height " + mat1.height() + " Width " + mat1.width());
fileLogger.writeEvent("process()","converted to cv_8uc4");
Log.d("OPENCV","Channels " + mat1.channels());
Imgproc.cvtColor(mat1, mat2, Imgproc.COLOR_RGB2HSV_FULL);
SaveImage(mat2, "-COLOR_RGB2HSV_FULL");
Log.d("OPENCV","COLOR_RGB2HSV Height " + mat2.height() + " Width " + mat2.width());
Log.d("OPENCV","Channels " + mat2.channels());
//Core.inRange(mat2, RED_LOWER_BOUNDS_HSV, RED_UPPER_BOUNDS_HSV, mat3);
Log.d("OPENCV","mat2 Channels " + mat2.channels() + " empty " + mat2.empty());
Log.d("OPENCV","mat3 Channels " + mat3.channels() + " empty " + mat3.empty());
Core.inRange(mat2, new Scalar(0,100,150), new Scalar(22,255,255), mat3);
fileLogger.writeEvent("process()","Set Red window Limits: ");
SaveImage(mat3, "-red limits");
These are the 2 errors I get when the command runs
E/cv::error(): OpenCV Error: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /home/maksim/workspace/android-pack/opencv/modules/imgproc/src/color.cpp, line 7349
E/org.opencv.imgproc: imgproc::cvtColor_10() caught cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/imgproc/src/color.cpp:7349: error: (-215) scn == 3 || scn == 4 in function void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
3 images are saved in the pictures directory as expected.
My logging produces the following
D/OPENCV: mat2 Channels 3 empty false
D/OPENCV: mat3 Channels 4 empty false
I have tried two different phones, tried adjusting the resolution down. I have reinstalled the OpenCV module in case it was not installed correctly. I have made the images all 3 channels, all 4 channels.
So after a week of debugging it was the most stupidest of mistakes!
Within the SaveImage function
Imgproc.cvtColor(mat, mIntermediateMat, Imgproc.COLOR_RGBA2BGR, 3);
This was what was causing the issue.
After the Core.inRange was the SaveImage function. Core.inRange dropped the channels to 1 - the fileLogger did not flush the last log, If I had used Log instead I probably would have picked it quicker.
public void SaveImage (Mat mat, String info) {
Mat mIntermediateMat = new Mat();
Imgproc.cvtColor(mat, mIntermediateMat, Imgproc.COLOR_RGBA2BGR, 3); <--Here bad
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String filename = "ian" + info + ".png";
File file = new File(path, filename);
Boolean bool = null;
filename = file.toString();
bool = Imgcodecs.imwrite(filename, mIntermediateMat);
if (bool == true)
Log.d("filesave", "SUCCESS writing image to external storage");
else
Log.d("filesave", "Fail writing image to external storage");
}
I am drawing a Trend chart(line) but in my case the legend Text is really big so it there any way that I can word wrap the text.
I think you can use the string functions that you can find in this link to manipulate the titles of series and try to reduce their length. I have made a suggestion code that I think can help you achieve as you want:
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scLine
TChart1.AddSeries scLine
Dim i As Integer
TChart1.Series(0).AddXY 0, 30, "", clTeeColor
TChart1.Series(0).AddXY 10, 100, "", clTeeColor
TChart1.Series(1).AddXY 0, 50, "", clTeeColor
TChart1.Series(1).AddXY 50, 120, "", clTeeColor
TChart1.Series(0).Title = "DDDDAAAAFFFFLLLLRRRRSSSS"
TChart1.Series(1).Title = "AAAALLLLSSSSTTTTEEEERRRR"
SeriesTitleWarp TChart1.SeriesCount
End Sub
Private Sub SeriesTitleWarp(ByVal count As Long)
'Replace some chars of string title to ...
Dim i As Integer
For i = 0 To count - 1
'Calculate the size of string
Dim LenString As Integer
LenString = Len(TChart1.Series(i).Title)
'First replace the Left chars for ...
Dim TitleString As String
TitleString = TChart1.Series(i).Title
Mid$(TitleString, 10, 3) = "..."
'After cut the string
TitleString = Left(TitleString, 12)
'Assign new title to series.
TChart1.Series(i).Title = TitleString
Next i
End Sub
Revising your requirements, I suggest you an other alternative that reduces the Legend Text, but the title of series remains intact. Could you please check if next code works as you want?
Private Sub Form_Load()
TChart1.Aspect.View3D = False
TChart1.AddSeries scLine
TChart1.AddSeries scLine
Dim i As Integer
TChart1.Series(0).AddXY 0, 30, "", clTeeColor
TChart1.Series(0).AddXY 10, 100, "", clTeeColor
TChart1.Series(1).AddXY 0, 50, "", clTeeColor
TChart1.Series(1).AddXY 50, 120, "", clTeeColor
TChart1.Series(0).Title = "DDDDAAAAFFFFLLLLRRRRSSSS"
TChart1.Series(1).Title = "AAAALLLLSSSSTTTTEEEERRRR"
' TChart1.Legend.ShapeBounds.Right = 100
TChart1.Legend.Left = 100
TChart1.Legend.CustomPosition = True
TChart1.Legend.Width = 100
End Sub
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
If ValueIndex <> -1 Then
'Calculate the size of string
Dim LenString As Integer
LenString = Len(TChart1.Series(ValueIndex).Title)
'First replace the Left chars for ...
Dim TitleString As String
TitleString = TChart1.Series(ValueIndex).Title
Mid$(TitleString, 10, 3) = "..."
'After cut the string
TitleString = Left(TitleString, 12)
'Assign new text to LegendText
LegendText = TitleString
End If
End Sub
I hope will helps.
Thanks.
wondering, if someone can help. I've written this code, which will generate an CSV file spreadsheet and save it to a specified location. I want to display a "Save as" dialogue box by reading the file from the stored location and then asking user, where they want to store it. The excel file is not generated and after click on "Export To CSV" in next window, it will show undefined as a massege! However my problem is the code i've written seems to be outputting the file directly to my browser, so i get all the contents of the CSV file on my browser screen, not displaying the save as dialogue box as expected!
Here is my Code
public ActionResult ExportToCSSReport(List<CEPMobility.CEPServiceProxy.CSSReport> Report)
{
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, System.Text.Encoding.UTF8);
writer.WriteLine("PROJECT NAME,CSS ID,CSS Name,Customer Reprentative Name,CSS Recived Date,CSI,TOP 3 STRENGTH,TOP 3 OFI,Any Other COMMENT");
foreach (CEPMobility.CEPServiceProxy.CSSReport objreport in Report)
{
writer.WriteLine("\"" + objreport.PROJECT_NAME + "\",\"" + objreport.CSS_ID + "\",\"" + objreport.CSS_NAME + "\",\"" + objreport.CUST_REP_NAME + "\",\"" + objreport.CSS_RECIEVED_DT + "\",\"" + objreport.CSI + "\",\"" + objreport.TOP_3_STRENGTH + "\",\"" + objreport.TOP_3_OFI + "\",\"" + objreport.COMMENT + "\"");
}
writer.Flush();
output.Seek(0, SeekOrigin.Begin);
return File(output, "text/csv", "CSSReport.csv");
}
In response to gor, it would show the same undefined message at the top:
public ActionResult ExportToCSSReport(List<CEPMobility.CEPServiceProxy.CSSReport> Report)
{
CEPServiceProxy.CEPDataServiceClient client = null;
client = new CEPServiceProxy.CEPDataServiceClient();
lstCSSReport = client.GetCSSReport(cSS_NAME, in_Cust_ID).ToList();
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, System.Text.Encoding.UTF8);
writer.WriteLine("PROJECT NAME,CSS ID,CSS Name,Customer Reprentative Name,CSS Recived Date,CSI,TOP 3 STRENGTH,TOP 3 OFI,Any Other COMMENT");
foreach (CEPMobility.CEPServiceProxy.CSSReport objreport in Report)
{
writer.WriteLine("\"" + objreport.PROJECT_NAME + "\",\"" + objreport.CSS_ID + "\",\"" + objreport.CSS_NAME + "\",\"" + objreport.CUST_REP_NAME + "\",\"" + objreport.CSS_RECIEVED_DT + "\",\"" + objreport.CSI + "\",\"" + objreport.TOP_3_STRENGTH + "\",\"" + objreport.TOP_3_OFI + "\",\"" + objreport.COMMENT + "\"");
}
writer.Flush();
output.Seek(0, SeekOrigin.Begin);
Response.AddHeader("Content-Disposition", "attachment;filename=CSSReport.csv");
return File(output, "text/csv", "CSSReport.csv");
}
You shoud add Content-Disposition header to your response. Like this:
Response.AddHeader("Content-Disposition", "attachment;filename=CSSReport.csv");