如何在应用程序路径中创建Excel文件31055.xlsx [英] How to create excel file 31055.xlsx in application path

查看:120
本文介绍了如何在应用程序路径中创建Excel文件31055.xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体中工作c#visual studio 2015



我有excel文件xlsx,名称是3105.xlsx,我需要在应用程序中创建它



路径。



如何在应用程序路径中创建excel文件



我的代码



  public   void  CreateSheetIfNotExists()
{
使用(System.Data。 OleDb.OleDbConnection databaseConnection = new System.Data.OleDb.OleDbConnection())
{

DataTable schemaTable = 默认(数据表);
databaseConnection.ConnectionString = Provider = Microsoft.ACE.OLEDB.12.0; + < span class =code-string>
数据源= D:\\Book3105.xlsx; Mode = ReadWrite;扩展属性= Excel 12.0 Xml;< /跨度>;

databaseConnection.Open();

schemaTable = databaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object [] {
null
null
Sheet1 $
});

if (schemaTable.Rows.Count == 0
{
string SQLDDLCommand = 创建表[Sheet1](UserID INTEGER,UserName CHAR(255));
System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand(SQLDDLCommand,databaseConnection);
excelCommand.ExecuteNonQuery();

}

databaseConnection.Close();
}
}





我的尝试:



如何在应用程序路径中创建Excel文件31055.xlsx 

解决方案

< blockquote>
});

if (schemaTable.Rows.Count == 0
{
string SQLDDLCommand = CREATE TABLE [Sheet1](UserID INTEGER,UserName CHAR(255));
System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand(SQLDDLCommand,databaseConnection);
excelCommand.ExecuteNonQuery();

}

databaseConnection.Close();
}
}





我的尝试:



如何在应用程序路径中创建Excel文件31055.xlsx 


这个问题是在几天前提出的,是你吗?

Quote:

如何在应用程序路径中创建Excel文件31055.xlsx



Windows出于安全原因主动防止这种情况发生,它是为了防止恶意软件改变应用程序。没有应用程序在应用程序路径中存储自己的配置,有一个原因。
只有主管可以这样做,普通用户不能。



为什么你绝对需要将这个Excel文件存储在app目录中?


I work in windows form c# visual studio 2015

I have excel file xlsx and name is 3105.xlsx and i need to create it in application

path .

how to create excel file in application path

my code

public void CreateSheetIfNotExists()  
       {  
           using (System.Data.OleDb.OleDbConnection databaseConnection = new System.Data.OleDb.OleDbConnection())  
           {  
  
               DataTable schemaTable = default(DataTable);  
               databaseConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=D:\\Book3105.xlsx;Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;";  
  
               databaseConnection.Open();  
  
               schemaTable = databaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] {  
           null,  
           null,  
           "Sheet1$"  
       });  
  
               if (schemaTable.Rows.Count == 0)  
               {  
                   string SQLDDLCommand = "CREATE TABLE [Sheet1] (UserID INTEGER, UserName CHAR(255))";  
                   System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand(SQLDDLCommand, databaseConnection);  
                   excelCommand.ExecuteNonQuery();  
                     
               }  
              
               databaseConnection.Close();  
           }  
       }



What I have tried:

How to create Excel file 31055.xlsx in application path

解决方案

" }); if (schemaTable.Rows.Count == 0) { string SQLDDLCommand = "CREATE TABLE [Sheet1] (UserID INTEGER, UserName CHAR(255))"; System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand(SQLDDLCommand, databaseConnection); excelCommand.ExecuteNonQuery(); } databaseConnection.Close(); } }



What I have tried:

How to create Excel file 31055.xlsx in application path


This question was asked a few days ago, is it you ?

Quote:

How to create Excel file 31055.xlsx in application path


Windows actively prevent this from happening for security reasons,it is to prevent malware from altering apps. No app store its own configuration in the app path, there is a reason.
Only supervisors can do this, normal users can't.

Why do you absolutely need to store this Excel file in app directory ?


这篇关于如何在应用程序路径中创建Excel文件31055.xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆