我想在文件中添加特定的文本行.具体在两个边界之间.
如果我想在item1的边界之间添加一行,它会是什么样子的一个例子:
[item1]
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 7
//Add a line here in between the specific boundaries
[/item1]
[item2]
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 8
2550 coins 995 200000 7
2550 coins 995 200000 7
[/item2]
[item3]
2550 coins 995 200000 7
2550 coins 995 200000 7
2550 coins 995 200000 …Run Code Online (Sandbox Code Playgroud) 这是发生的事情:

xlValues被设置为Excel.Range对象.
我也试过以下,都给了我同样的错误:
//xlValueRange = xlSheet...
.get_Range("A1:A5,A15:A25,A50:A65");
.UsedRange.Range["A1:A5,A15:A25,A50:A65"];
.Range["A1:A5,A15:A25,A50:A65"];
xlApp.ActiveWorkbook.ActiveSheet.Range["A1:A5,A15:A25,A50:A65"];
//I have also tried these alternatives with ".Select()" after the brackets and
//", Type.Missing" inside the brackets
//This works though...
xlSheet.Range["A1:A5"];
Run Code Online (Sandbox Code Playgroud)
我正在尝试重新着色excel表中的特定单元格,我已经通过使用两个循环找到了解决方案,但它太慢了.通过一个30 000个单元格的列需要几分钟.
我之前从未做过这样的事情,而且我用这个教程让我开始.
此解决方案使用bool数组,将要着色的单元格设置为true.(recolored)
//using Excel = Microsoft.Office.Interop.Excel;
xlApp = new Excel.Application();
xlApp.Visible = true;
xlBook = xlApp.Workbooks.Add(Type.Missing);
xlSheet = (Excel.Worksheet)xlBook.Sheets[1];
for (int i = 1; i < columns + 1; i++)
{
for (int j = 1; j < rows + 1; …Run Code Online (Sandbox Code Playgroud) ETC ="预计完成时间"
我正在计算运行循环所需的时间并向用户显示一些数字,告诉他/她大约需要多长时间才能完成整个过程.我觉得这是一个普通的事情,每个人偶尔会这样做,我想知道你是否有任何指导方针.
这是我目前正在使用的一个例子:
int itemsLeft; //This holds the number of items to run through.
double timeLeft;
TimeSpan TsTimeLeft;
list<double> avrage;
double milliseconds; //This holds the time each loop takes to complete, reset every loop.
//The background worker calls this event once for each item. The total number
//of items are in the hundreds for this particular application and every loop takes
//roughly one second.
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//An item has been completed!
itemsLeft--;
avrage.Add(milliseconds);
//Get …Run Code Online (Sandbox Code Playgroud)