c#,excel,excel-interopRelated issues-Collection of common programming errors


  • vasa911
    c# ftpwebrequest
    I’m making a FTP client and trying to upload file to server (~300 Mb), but i get following error when nearly 100 Mb of the file were transfered:The underlying connection was closed: An unexpected error occurred on a receive.Here’s my code:private void UploadFile(string filepath, string filename){try{FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(“ftp://” + server + “/” + filename);//ftp.KeepAlive = false;//ftp.Timeout = 1000000;//ftp.UsePassive = true;//ftp.ReadWriteTimeout = 100000;Pat

  • Eray Geveci
    c# asp.net sql
    Possible Duplicate:Unexpected database output when using INNER JOIN hello i have a sql query like this:SELECT DISTINCT r.BEZEICHNUNG AS BEZEICHNUNG, r.ID AS ID, ra.BEZEICHNUNG AS raumBEZEICHNUNG, ra.ID AS raumID FROM RAZUORDNUNG rz right join RAUMATTRIBUTE ra ON rz.RAUMATTRIBUTE_ID = ra.ID right join RAUM r ON rz.RAUM_ID = r.ID WHERE ….i write the results in a list: strasseObject.Add(new RAUM(){RaumName = rdr[“BEZEICHNUNG”].ToString(),RaumID = rdr[“ID”].ToString(),RaumAttribute = rdr[“raum

  • Diana Dimitrova
    c# asp.net-mvc-3 wcf
    When i try to access web service from the development server, it returns the error below. When I access the same service from my local machine, it works fine. Do you have idea what might be the reason? Thank you very much in advance!System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed. —> System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.at System.Net.HttpWebRequest.GetResponse()at System.Serv

  • Jez
    c# .net exception error-handling
    It’s often said that you shouldn’t use exceptions for regular error handling because of bad performance. My guess is that that bad performance is caused by having to instantiate a new exception object, generate a stack trace, etc. So why not have lightweight exceptions? Code like this is logically sound:string ageDescription = “Five years old”; try {int age = int.Parse(ageDescription); } catch (Exception) {// Couldn’t parse age; handle parse failure }And yet we’re recommended to use TryParse

  • agmcleod
    c# .net
    Solved.The string for the keyvalue pairList<KeyValuePair<string, string>> responses = new List<KeyValuePair<string, string>>();Is like so: 2011-6-8 2:19:0 || urlI sorted the List by using the following:responses.OrderByDescending(s => DateTime.Parse(s.Key.Split(new string[] { ” || ” }, StringSplitOptions.None)[0])).ToList();Thanks for the quick responses everyone.Problem:I have a list that contains a key value pair like so: List<KeyValuePair<string, string>>

  • kubal5003
    c# garbage-collection
    for some time I was trying to debug my algorithm that synchronizes data between two databases. Everything worked ok for a few months of everyday use and recently strange things started to happen eg:”DisableBuyButton” property was sometimes set to true, while this was explicitly set to false in the configuration file (I have stepped through the algorithm way too many times to find something odd – found nothing and while doing this on my machine everything was ok) products were assigned to differe

  • Yuck
    c# sockets networking
    This is related to c# Sockets. I’m developping a socket program. But there is one problem in my software. I cannot connect to computers which are connected to internet via theirs local network. But I can connect to computers that are uses internet alone. Be more descriptive, Consider that 5 computers connects internet via a modem that uses 1 ip address. When I try to reach one of these computers, API connects to modem via its ip address. But there is no response. Because a modem don’t respond

  • vince
    c# excel
    i have a situation where i load a dataset with excel file. All the worksheet are loaded as datatable with the appropriate worksheet name as datatable name. What i am trying to do is get this datatable value using column name. But i am not get error saying”Column ‘Execute’ does not belong to table Sheet1″.While loaded excel to datatabel i have used HDR=YES and IMEX=1. I also tried with HDR=NO. nothing is working. below code is to write excel to datatableforeach (Microsoft.Office.Interop.Excel

  • leppie
    c# booksleeve
    I am having difficulty with the 1.1.0.5 version of Booksleeve in VS2010 working the way I intend to use it. What’s happening is after perform and wait for an operation, Booksleeve sometimes leaves the connection in a closed state, so operations down stream throw exceptions.The simplest issue I am having is this:static void Main(string[] args) {Func<RedisConnection> getNewRedisConnection = () =>{RedisConnection conn = new RedisConnection(“Belasco”);conn.Error += (obj, eArgs) => { thr

  • apros
    c# sql-server clr clrstoredprocedure
    I have a stored procedure in SQL Server 2008 CLR project. This function call a console application with a parameter that contain some xml. [Microsoft.SqlServer.Server.SqlProcedure()] public static SqlInt32 ExecuteApp(SqlString utilPath, SqlString arguments, ref SqlString result) {ProcessStartInfo info = new ProcessStartInfo(“cmd.exe”);Process p = new Process();try{//ProcessStartInfo to run the DOS command attribinfo.RedirectStandardOutput = true;info.RedirectStandardError = true;info.UseShell

  • banditKing
    excel applescript osx-snow-leopard automator
    I have about 400 excel files. I want to insert a column just before the first column in the existing file and then insert the name of the file into each row of that column.I know a little bit of Applescript and based on that I wrote this script so that I can drop some files onto the script and it will execute the script on each one of those files.I was wondering if someone could help me in completing the “TO DO” lines. Upon execution this script gives me dialogue boxes with the path of files tha

  • molnardenes
    excel vba macros duplicate-removal
    Is it possible to use a function in Excel 2003 to delete an entire row if it’s the same as the previous one? For example:apple apple plum vinegar apple banana banana banana appleI want to delete #2, 7# and #8, but I don’t want #5 and #9 to be deleted. I want to delete a duplicated entry ONLY IF it’s the next one. I hope I managed to keep it clear to you. If there isn’t a function, how can I do that in VBA? Thanks in advance!

  • user25830
    excel excel-vba combobox named-ranges
    Can anyone Please help resolve an issue with ReferToRange in my code. I have attached an example. I am getting a runtime error 1041 application defined or object defined error when the MAIN is called. I am linking a combobox listfillrange to 3 named ranges depending on the value of a cell. The three ranges are dynamic(have an offset formula). the combobox is a different sheet than the named ranges Please helpSub MAIN() Dim PT As Range Dim i As LongWith Sheet3 ‘ Unique SPPsetNames .Range(“a6”)Se

  • vince
    c# excel
    i have a situation where i load a dataset with excel file. All the worksheet are loaded as datatable with the appropriate worksheet name as datatable name. What i am trying to do is get this datatable value using column name. But i am not get error saying”Column ‘Execute’ does not belong to table Sheet1″.While loaded excel to datatabel i have used HDR=YES and IMEX=1. I also tried with HDR=NO. nothing is working. below code is to write excel to datatableforeach (Microsoft.Office.Interop.Excel

  • user2985990
    excel vba excel-vba
    I am trying to set up a function so that whether I pass a blank cell or do not even select a cell for the argument it returns the function I am looking for. Here is my code:Function FinancialsAge(FirstBirthday As Date, BeginningDate As Date, Optional SecondBirthday As Variant) As StringIf IsMissing(SecondBirthday) = True Or SecondBirthday = vbNullString ThenFinancialsAge = Year(BeginningDate – FirstBirthday) – 1900 ElseIf SecondBirthday ThenFinancialsAge = (Year(BeginningDate – FirstBirthday) –

  • Siddharth Rout
    excel excel-vba
    I have the following code to select a column based on header.Dim rng1 As Range Set rng1 = Range(Range(“A1:Z1”).Find(“Name”), Range(“A1:Z1”).Find(“Name”).End(xlDown))When trying to use this range and set the XValue’s on a chartActiveChart.SeriesCollection(5).XValues = rng1I see the header too comes in the list.Wanted to know a way to select a column based on header and then remove the header element from it.

  • 0xA3
    c# asp.net excel
    I’m trying to create an excel file from ASP.NET. I assume this file is created somewhere temporary right? How can I get this location?

  • Skrealin
    excel vba ado
    This seems to be a fairly common problem but none of the the solutions I’ve found seem to work.I’m grabbing some data from SQL Server and copying it into a worksheet. Then I want to copy a range from the new data and do other stuff with it. All of this happens in a single vba function.My problem is when the function is run from Excel it moves onto the second part of the function without waiting for the query to return the required data.Of course the function works fine when I run it from the vba

  • Rocketq
    c# excel
    This is how I create chart:Excel.ChartObjects xlChartsq = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing); Excel.ChartObject myChartq = (Excel.ChartObject)xlChartsq.Add(10, 1000, 175, 310); Excel.Chart chartPageq = myChartq.Chart; myChartq.Select();And I have succesfully named primary axis this way, I have used MDSN`s code:Excel.Axis axis = myChartq.Chart.Axes( Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);axis.HasTitle = true; axis.AxisTitle.Text = “AXIS`s NAME”;It works as

  • iwishiwasacodemonkey
    excel vba excel-vba excel-2007
    Sub Macro1() Dim URL As String Dim Path As String Dim i As Integer For i = 2 To 50 If Range(“Prices!E” & i).Value <> 1 Then URL = Range(“Prices!D” & i).Text Path = Range(“Prices!F” & i).Text End If Sheet19.Activate With ActiveSheet.QueryTables.Add(Connection:= _”URL;” & URL _, Destination:=ActiveSheet.Range(“$A$1″)).Name = _”” & Path.FieldNames = True.RowNumbers = False.FillAdjacentFormulas = False.PreserveFormatting = True.RefreshOnFileOpen = False.BackgroundQuery = Tr

  • downwitch
    c# excel vsto excel-interop
    New to VSTO, know Excel’s model very well… I have using Excel = Microsoft.Office.Interop.Excel;at the head of my class, and the following simple call, which compiles correctly and even appears correct in intellisensedouble usedRows = (double)Excel.WorksheetFunction.CountA(oWks.Columns[1]);but fails at runtime with this exception’Microsoft.Office.Interop.Excel.WorksheetFunction’ does not contain adefinition for ‘CountA’about which I can find little further information. What am I missing?

  • RichardTheKiwi
    c# .net visual-studio interop excel-interop
    …Excel.Application oXL; Excel._Workbook oWB; Excel._Worksheet oSheet;oXL = new Excel.Application(); oWB = (Excel._Workbook)oXL.ActiveWorkbook; oSheet = (Excel._Worksheet)oWB.Sheets[1];oSheet.Cells[5,10] = “Value”;…yields this at crash:Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.at ConsoleApplication1.Program.Main(String[] args) in C:\Wherever\Visual Studio 2008\Projects\ConsoleApplication20\ConsoleApplication20\Program. cs:line 60I

  • Razor Storm
    c# excel excel-interop
    I have an excel addin class that has this function:public void testRibbon() {Excel.Workbook workbook = this.Application.ActiveWorkbook; Excel.Worksheet activeSheet = workbook.Sheets[1];Excel.Range range = activeSheet.get_Range(JOB_ID_FIELD + HEADER_ROW, TOTAL_STATUS_PERCENTAGE_KEY_FIELD + (10 + 1).ToString());range.get_Range(“C4”).Value = “test Ribbon complete”; }In the ribbon I added a button that when pressed will call testRibbon in a thread:private void process_Click(object sender, Ribbo

  • svick
    c# excel-interop
    I am creating an excel application with c#. Since I will maintain the excel file in urgency I want to keep its handler open. I want to keep the excel process id so I will be able to kill it in case the system crashs.How can I get the Excel Pid when creating it?

  • John Saunders
    c# excel interop excel-interop
    I’m trying to find the count of all cell with constants using Excel Interop assembly.On small files this works fine. However on larger files excel crashes.I tried it on a file with 206963 rows and 9 columns and excel crashed.Anyone know of a workaround? Is there a list of the limitations of the SpecialCells function and when it should not be used?The following is my code:public static int getConstantCount(Range myRange) //myRange = myWorksheet.UsedRange {try{ return myRange.SpecialCells(XlCe

  • user1546315
    c# excel excel-interop
    I have a C# program that is creating, writing, and saving an excel file using the Excel Interop. The problem is that if I don’t have the application quit immediately after saving and closing the excel file then the c# application gets an unhandled exception and crashes. Has anyone found a way to do this while being able to keep the host c# application open and running.Here is the code that handles everything involving the Excel Interopclass CreateExcelDoc {string newFormString = trialReportFor

  • user1546315
    c# excel excel-interop
    I am trying to save an excel file that was created and written to via a C# application using the Excel Interop. I have looked all over this site as others to find a code that properly works and I have yet to find one. My excel interop funciton uses a workbook, worksheet, app, and workshee_range object. Does anyone have any suggestions. The easier the solution the better. I’m a beginner to intermediate level C# programmer and an advanced solution will likely be out of my scope of knowledge.

  • D_Bester
    c# .net vb.net excel excel-interop
    I’ve seen a lot of articles and questions about how to be sure that Excel actually quits when you want it to and the process doesn’t stay alive. Here is a knowledge Base article describing the problem and Microsoft’s recommended solution. Essentially:’close files’Quit Excel xlApp.quit()’Release and collect garbage System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp) GC.Collect() GC.WaitForPendingFinalizers()Many people don’t recommend killing the process; See How to properly clea

  • Reynier
    c# interop excel-interop
    I found this code on Internet to create a Excel file using Interop library:object misValue = System.Reflection.Missing.Value; xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet.Cells[1, 1] = “http://csharp.net-informations.com”;xlWorkBook.SaveAs(“csharp-Excel.xls”, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue

  • user1067334
    c# asp.net excel impersonation excel-interop
    I am using the following piece of code to write into the excel file dynamically on a ASP.net form that can save the data table to excel.//Create Excel Object Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Open(target); Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];worksheet.Name = “Worksheet1”; excel.Visib

Web site is in building