我正在编写一个生成excel报告的程序,目前正在使用Microsoft.Interop.Excel引用.我的开发计算机上有Excel,但最终用户可能安装了Office,也可能没安装Office.如果最终用户计算机上未安装Office,或者此互操作服务是否与实际应用程序分开,此工具是否会失败?
我有一个DataTable我想要推送到DB.我希望能够说出来
myDataTable.update();
Run Code Online (Sandbox Code Playgroud)
但在阅读MSDN 文档后,显然这确实是逐行插入的.
应该注意的是,这些陈述不是作为批处理执行的; 每行都单独更新.
我有什么选择?
编辑:我正在使用SQL Server 2005
在我的应用程序中,我使用StreamWriter将数据流式传输到文件.在调用Close()方法之前,是否有任何字节实际写入文件?如果答案是否定的,无论流有多大,这都是正确的吗?
兰迪
我试图将DataGridView数据复制到Excel,我使用此代码:
public static void ExportToExcel(DataGridView dgView)
{
Microsoft.Office.Interop.Excel.Application excelApp = null;
try
{
// instantiating the excel application class
object misValue = System.Reflection.Missing.Value;
excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook currentWorkbook = excelApp.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet currentWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)currentWorkbook.ActiveSheet;
currentWorksheet.Columns.ColumnWidth = 18;
if (dgView.Rows.Count > 0)
{
currentWorksheet.Cells[1, 1] = DateTime.Now.ToString("s");
int i = 1;
foreach (DataGridViewColumn dgviewColumn in dgView.Columns)
{
// Excel work sheet indexing starts with 1
currentWorksheet.Cells[2, i] = dgviewColumn.Name;
++i;
}
Microsoft.Office.Interop.Excel.Range headerColumnRange = currentWorksheet.get_Range("A2", "G2");
headerColumnRange.Font.Bold = true;
headerColumnRange.Font.Color …Run Code Online (Sandbox Code Playgroud) 下面是我的示例文本文件
{
这是我的架构文件
[Sample File.txt]
ColNameHeader=True
Format=TabDelimited
CharacterSet=ANSI
Run Code Online (Sandbox Code Playgroud)
这是我迄今为止编写的用于尝试读取上述示例文件的代码,从上面的文本文件中读取的数据行应该返回以在 dataGridView 控件中显示。问题是,它作为单列返回,但我想使用这些空格作为列分隔符。我尝试了不同的字符分隔符,但没有成功。
public DataSet LoadCSV(int numberOfRows)
{
DataSet ds = new DataSet();
// Creates and opens an ODBC connection
string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + this.dirCSV.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
string sql_select;
OdbcConnection conn;
conn = new OdbcConnection(strConnString.Trim());
conn.Open();
//Creates the select command text
if (numberOfRows == -1)
{
sql_select = "select * from [" + this.FileNevCSV.Trim() + "]";
}
else
{
sql_select = "select top " + …Run Code Online (Sandbox Code Playgroud)