Tag: winforms

该格式不适用于Excel表格

我正在WinformsApplication,在那个应用程序中我有一个网格控件。 在GridControl中,我有一个格式为“F2”的双types列。 当我试图将网格导出为ex​​cel时,将显示格式(F2)而不是值(例如55.78)。 但是如果我设置格式为(0.00)而不是(F2)。 它的工作正常 。 请让我知道,为什么“F2”格式不适用? 或者是否可以通过excel支持“F2”?

如何将过滤的数据从SQL Server导出到Excel?

我有一个WinForm是为了筛选和显示我的数据库中的数据到它的DataGridView 。 为了过滤,我放置了一个combobox ,显示数据库中列的名称,并可以select,还有一个用户可以input关键字或短语的textbox 。 然后用户点击Filterbutton来执行过滤。 我也有一个button来导出数据库表到一个Excel文件。 我的过滤方法: protected void searchFilter() { DataTable dt; BindingSource bs = new BindingSource(); _db.conn(); _db.cmd.CommandText = "SELECT * FROM IncomingLog"; dt = _db.executeDT(); DataView dv = new DataView(dt); incomLogTableS.DataSource = dv; String cmbCat = cmbFilterIDLS.GetItemText(cmbFilterIDLS.SelectedValue.ToString()); String keyID = keyIDLS.Text; if (cmbCat != "Select Category") { if (cmbCat == "Received […]

Windows窗体input/保存到使用Excel的FilePath问题

我有一个简单的窗体与人的详细信息input.I使用文件path来保存条目(mydocuments / .csv文件)我在WF上的显示是一个标签 问题:我做的每个条目都保存在csv / excel文件中,在一个连续的行和标签上,当我点击“显示数据”我希望每个input行在标签显示分离任何帮助将不胜感激,新的这个游戏。 谢谢你我的代码: 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; namespace StringFilePath { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string FilePath = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar+ "mestring.csv"; private void btnAdd_Click(object sender, EventArgs […]

Excel到DataGridView

其他信息:Microsoft Office Access数据库引擎找不到对象“C:\ Users \ username \ Documents \ sampleData.xls”。 确保对象存在,并且正确拼写其名称和path名称。 该错误突出显示在 theDataAdapter.Fill(spreadSheetData); 这里是我使用的示例数据(用.csv,.xls,.xlsx试用) Name Age Status Children Johnny 34 Married 3 Joey 21 Single 1 Michael 16 Dating 0 Smith 42 Divorced 4 以下是相关的代码: 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; […]

在C#Windows窗体中使用OpenFileDialog打开Excel文件

我可以select一个Excel文件,但点击打开后,excel文件不会出现。 我该怎么办? 我还是新的OpenFileDialog,这将是很好的,如果有人可以告诉我应该添加,使Excel文件出现后点击打开。 从http://www.c-sharpcorner.com/uploadfile/mahesh/openfiledialog-in-c-sharp/修改 这是我的代码: private void BrowseButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = @"C:\"; openFileDialog1.Title = "Browse Text Files"; openFileDialog1.CheckFileExists = true; openFileDialog1.CheckPathExists = true; openFileDialog1.DefaultExt = "txt"; openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.ReadOnlyChecked = true; openFileDialog1.ShowReadOnly = true; if (openFileDialog1.ShowDialog() […]

windows窗体devise连接excel时破坏

当我连接到这个代码的Excel文件(正是当_conn.Open();) _conn = new OleDbConnection(_connectionStrting); _conn.Open(); DataTable dt = _conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); String[] sheetNames = new String[dt.Rows.Count]; int i = 0; foreach (DataRow row in dt.Rows) { sheetNames[i] = row["TABLE_NAME"].ToString(); comboBox2.Items.Add(sheetNames[i]); i++; } _conn.Close(); 我的Windows窗体devise(在C#)得到一些问题,如解决scheme的变化和元素的大小比以前更小,元素的位置改变运行时间。我使用其他方式连接到Excel(使用Excel库),现在我不'没有问题,但我很好奇这个问题。有人告诉我为什么会发生这种情况?

从Excel工作表添加一列到WinForms

我在智慧的结尾,试图解决这个问题! 我有两个(看似相关的)问题: 问题1 – 我有一张工作表的Excel工作表。 在Form1中有一个浏览button,浏览Excel工作表。 所有这一切运作良好。 当我点击确定button,它打开了Form2,这也是正确的。 在Form2_Load事件中,我编写了代码来处理我需要使用Excel工作表(这是问题#2)执行的逻辑。 发生什么事情是,当我在浏览窗口上单击确定,它也打开了Excel表,我不想要的。 这是整个事情的代码: Excel.Application xlAppl = new Excel.Application(); xlAppl.Visible = true; Excel.Workbook myWorkbook = xlAppl.Workbooks.Open(Form1.globalClass.GlobalVar); //Gets the path to the excel sheet Excel.Worksheet myWorkSheet = (Excel.Worksheet)myWorkbook.Worksheets[1]; Excel.Range range = (Excel.Range)myWorkSheet.Columns[1]; if(myWorkSheet != null) //This is the logic for problem#2 so please discard this for now. 我基本上不想打开Excel工作表。 你能看到这个问题是什么? […]

如何在Excel文件的列中searchstring

我有一个Excel文件有一个列名称( name ),其中有以下条目: VIPIN VIPIN VIPIN VIPIN 我想统计我的string是"vipin"的name列中的条目。 使用OLEDB数据提供者。

在C#中创buildexcel文件

我的第一次使用C#的excel文件的经验。 作为一个演示,我在excel文件中写了一行,它工作,但现在我试图插入DataTable的所有行,但它给出了以下错误: “HRESULT:0x800A03EC” 这里是代码: for (int i = 0; i < table.Rows.Count; i++) { xlWorkSheet.Cells[i, 1] = table.Rows[i]["Ref"].ToString(); xlWorkSheet.Cells[i, 2] = table.Rows[i]["Name"].ToString(); } 请告诉我如何解决?

我怎样才能在Excel文本框中设置多行文本使用C#

在这里我的代码: using Excel = Microsoft.Office.Interop.Excel; private void button1_Click(object sender, EventArgs e) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook wb = xlApp.Workbooks.Add(System.Type.Missing); Excel.Worksheet ws = (Excel.Worksheet)wb.Sheets[1]; xlApp.Visible = true; Excel.Shape textBox = ws.Shapes.AddTextbox( Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 10 + 10 + 10, 36, 600, 100); textBox.TextFrame.Characters(System.Type.Missing, System.Type.Missing).Text = "testing"; xlApp.ActiveWindow.Activate(); xlApp.UserControl = true; ws = null; wb = null; […]