This project has moved. For the latest updates, please go here.

Problem sending a command to the program

Nov 29, 2010 at 7:23 PM

I have a relatively simple process where I am building a workbook that contains a column that is incremented from a starting number.  For some reason, I get the the titled error and then get "The converted failed to save the file."  Not sure what is going on.  I had this working on another pc, but have not been able to get this to work here.  Any ideas?

Code:

			ExcelPackage pck = new ExcelPackage();
			var ws = pck.Workbook.Worksheets.Add("Manual Receipts");
			
			ws.Cells["A1"].Value = " SpaceNeedle Manual Receipt Form";

			using (ExcelRange r = ws.Cells["A1:F1"])
				{
				r.Merge = true;
				r.Style.Font.SetFromFont(new Font("Arial", 18, FontStyle.Italic));
				r.Style.Font.Color.SetColor(Color.DarkRed);
				r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
				//r.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
				//r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(23, 55, 93));
				}
//			ws.Column(1).BestFit = true;
			ws.Column(1).Width = 17; 
			ws.Column(5).Width = 20;


		ws.Cells["A2"].Value = "Date Produced";

			ws.Cells["A2"].Style.Font.Bold = true;
			ws.Cells["B2"].Value = DateTime.Now.ToShortDateString();
			ws.Cells["D2"].Value = "Quantity";
			ws.Cells["D2"].Style.Font.Bold = true;
			ws.Cells["E2"].Value = txtReceiptQty.Text;

			ws.Cells["C4"].Value = "Receipt Number";
			ws.Cells["C4"].Style.WrapText = true;
			ws.Cells["C4"].Style.Font.Bold = true;

			int rowNbr = 5;
			for (int entryNbr = 1; entryNbr <= qtyReceipts; entryNbr += 1)
			{
			ws.Cells["B" + rowNbr].Value = entryNbr;
			ws.Cells["C" + rowNbr].Value = begNbr + entryNbr - 1;
				rowNbr += 1;
			}

		Response.BinaryWrite(pck.GetAsByteArray());
		Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
		Response.AddHeader("content-disposition", "attachment;  filename=ReceiptOrderForm.xlsx");

Coordinator
Nov 30, 2010 at 6:40 AM

Your code seems to work fine (in 2.8). Try a Response.Clear() before you do the Response.BinaryWrite and see if that helps.

Jan

Nov 30, 2010 at 9:34 PM

Thanks for the feedback.

I tried the Respone.Clear and I get an error box that says:

Excel found unreadable content in 'ReceiptOrderForm[3].xlsx'.  Do you want to recover  the contents of the workbook.  If you trust the source of this workbook, click yes.

I said yes and it opened it up correctly. 

I also ran it and did save instead of open and I got the above message, and when I opened it, Excel repaired the file, but did not give me any information on what it reparied.

 

I am using Excel 2010, it that makes any difference.

Coordinator
Dec 1, 2010 at 6:50 AM

I don't think Excel 2010 will make any difference. Try to add a Response.End() at the end like in this discussion...

http://epplus.codeplex.com/Thread/View.aspx?ThreadId=223843

Jan

Dec 1, 2010 at 1:14 PM

Progress!!  I am still getting the dialog box with "There was a problem sending a command to the program  ", but it will go ahead and start excel and create the workbook and sheet.  The popup will be troublesome.

Is there a way to use this to create a spreadsheet without having excel loaded on the local pc?

Joel WZ

Coordinator
Dec 2, 2010 at 2:45 PM

I think you have to have Excel on the local PC.