我一直在使用该Microsoft.Office.Interop.Excel库打开Excel,刷新一些查询并保存.我遇到的问题是,只有当每台计算机都具有与PC上安装的项目中选择的Excel库相同的Excel库时,这才会起作用.
我看到NPOI可以http://npoi.codeplex.com/documentation读取和写入数据到Excel,但是开放/刷新/保存更简单的任务怎么样,NPOI可以处理这个吗?
如果您使用此语法,我似乎可以打开我的Excel文件,但刷新查询和保存呢?
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
private void button1_Click(object sender, EventArgs e)
{
HSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"c:\test.xls", FileMode.Open, FileAccess.Read))
{
hssfwb= new HSSFWorkbook(file);
}
Run Code Online (Sandbox Code Playgroud) 我将值传递给存储过程,但它一直给我一个错误错误,将数据类型nvarchar转换为int.需要更改哪些内容才能删除错误?下面是我的实际调用和存储过程
private static string ReturnPhoneNumber()
{
string username = "Roy Orbinson";
string databaseConnection = "Data Source=EmployeeServer;Initial Catalog=StoreInfo;Integrated Security=True;MultipleActiveResultSets=True";
SqlConnection connection = new SqlConnection(databaseConnection);
SqlCommand command = new SqlCommand("GimmeThatPhoneNumber", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@username", username);
connection.Open();
var result = Convert.ToString(command.ExecuteScalar());
connection.Close();
return result;
}
Run Code Online (Sandbox Code Playgroud)
SQL:
[dbo].[GimmeThatPhoneNumber]
(
@username int
)
as
Set NoCount On
SELECT phonenumber
FROM personelinformation
where employeename = @username
Run Code Online (Sandbox Code Playgroud) 我想使用C#访问我的Outlook发送文件夹,并将邮件移动到我的PST中名为Archive的文件夹中.这是我正在使用的代码,但是我遇到了多个编译错误.这里有更多编码经验的人知道如何实现这一目标吗?
static void MoveMe()
{
try
{
_app = new Microsoft.Office.Interop.Outlook.Application();
_ns = _app.GetNamespace("MAPI");
_ns.Logon(null, null, false, false);
Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
Outlook.Items SentMailItems = SentMail.Items;
Outlook.MailItem newEmail = null;
foreach (object collectionItem in SentMailItems)
{
moveMail.Move(Archive);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
_ns = null;
_app = null;
_inboxFolder = null;
}
}
Run Code Online (Sandbox Code Playgroud)
评论中的错误列表:
Only assignment, call, increment, decrement, and new object expressions can be used as a statementThe type or namespace name 'Emails' could not be …我需要在我的文件名中删除下划线和所有字符.文件名的语法如下:
<username>_<NameofFile>_<InstructorName>_<ClassName>.xls
Run Code Online (Sandbox Code Playgroud)
我想保留一切但是这<username>_部分.
我尝试使用.Split如下:
string newfilename = file.Split('_')[1];
Run Code Online (Sandbox Code Playgroud)
但这一切都放弃了,只保留了<NameOfFile>.
怎么能实现这一目标?
如何通过代码更改文本文件编码?我正在使用此代码实际创建文件本身,但如何更改编码(更改为 UTF-8 w/o BOM)
string path = @"E:\Test\Example.txt";
if (!File.Exists(path))
{
File.Create(path);
}
Run Code Online (Sandbox Code Playgroud) 我想查看我们的主列表中的框列表,但是我们的非现场列表中没有标记为异地.
Select boxID, boxlocation
From masterList
WHERE boxlocation NOT IN (
Select boxID FROM offsiteList
)
Run Code Online (Sandbox Code Playgroud)
但是,我的2个列表已经损坏或我的查询返回不准确的结果.在我逐行检查列表之前,想要检查这是一个很好的查询...
我试图显示进程何时开始以及何时完成的时间戳,但我的时间从不增加(即使现实中的时间确实如此)
DateTime now = DateTime.Now;
txt1.AppendText(now + Environment.NewLine);
//Lengthy process that usually takes 2 - 3 minutes
txt1.AppendText(now);
Run Code Online (Sandbox Code Playgroud)