Tag: c#

c# – open excel workbook with different working directory

I am trying to open an Excel workbook from the temp directory, but specify an alternative working directory so that when the user goes to save the workbook the default save location is not the temp folder. Here’s what I am trying Process.Start(“EXCEL.EXE”, string.Format(“\”{0}\” /p \”{1}\””, workbookPath, desktopPath); Excel opens the workbook, but the /p […]

Why is wrapping inconsistent in C# Excel Interop?

Using this code: var avgOrderAmountHeaderCell = (Range)_xlSheetDelPerf.Cells[DEL_PERF_COLUMN_HEADER_ROW, AVG_ORDER_AMOUNT_COLUMN]; avgOrderAmountHeaderCell.Value2 = String.Format(“Avg Order{0}Amount”, Environment.NewLine); avgOrderAmountHeaderCell.WrapText = true; var avgPackageCountHeaderCell = (Range)_xlSheetDelPerf.Cells[DEL_PERF_COLUMN_HEADER_ROW, AVG_PACKAGE_AMOUNT_COLUMN]; avgPackageCountHeaderCell.Value2 = String.Format(“Avg Package{0}Count”, Environment.NewLine); avgPackageCountHeaderCell.WrapText = true; …I get this result (column header on left looks fine, while the one on the right has an “empty line” between the second and third wrapped […]

Highlighting cells/making them bold in Excel

In a group project I have to write a table to an Excel sheet. This I have done but I need to highlight the table area where the data goes, as can be seen on these pictures: https://gyazo.com/51c57897d9a1ce8df000d6ff0f18de20 https://gyazo.com/bcc879cd7d1c5f12ccb853490dca22f2 The first picture shows how it should look without data, and the second picture shows my […]

Importing Excel to DataGrid then save to MySQL database

When I import the Excel file into dataGridView1 and click ‘Update’ all the data isn’t storing into my database: Database pic My rota form Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Data.OleDb; using System.Data.SqlClient; namespace Login { public partial class […]

Microsoft Excel cannot open or save any more documents on Unit Test

There are a lot of posts about this, but with asp.net, I have checked them, but I couldn’t find anything that worked for me. There is a test in our application that access an excel file, like this: Excel.Application _excelApp = new Excel.Application { Visible = false }; // get a new workbook _workbook = […]

Error when OleDB(ACE) Read the .xls file

string connStr = @”Provider=Microsoft.ACE.OLEDB.12.0;Data Source=” + path + “;Extended Properties=\”Excel 8.0;HDR=Yes;IMEX=1\”;”; OleDbConnection MyConnection; OleDbCommand MyCommand = new OleDbCommand(); MyConnection = new OleDbConnection(@connStr); MyConnection.Open(); // Here the error come… Im try to using this connStr to connect to My xls file. The problem was “External table is not in the expected format.” Im have aleady installed […]

Close and open an excel workbook without flickering

I have been trying to achieve this from my application level addin but some how not able to get this right. Below are the steps I am trying to achieve on click of an application level addin button: Open an existing Excel file in current application. Do some refresh. After refresh close that (with Save […]

Import multiple XML files into Excel

I found this article: How can you programmatically import XML data into an Excel file? which shows how to import an XML file into Excel. My question is how do I import multiple XML files into multiple sheets in one workbook? The “OpenXML()” method appears to relate to the Workbooks collection only, and creates a […]

Need to get bullets from word tables to excel using interop

So I’ve been trying to learn how to use Interop (and programming in general for that matter). Basically I have these tables in my Word docs that I need to export to Excel. I’ve gotten the basic text to export to Excel, but my tables in Word have a fair amount of formatting, mainly bulleted […]

Fetch maximum number of columns for a specific set of rows

If I want to fetch the max number of columns for a set of rows in Excel, using Visual Studio, how would this be done? Here is my current attempt which yields the maximum number of columns across the whole sheet instead of the specified rows. here are my attempts at this. All the necessary […]

MS Excel Spreadsheet is the best Office Software, Excel VBA and Excel Formulas make Spreadsheet work faster.