小编Har*_*rry的帖子

将特定范围的excel单元格从一个工作表复制到另一个工作表

我正在编写一个C#程序,它将一系列单元格从一个工作簿的工作表复制到另一个工作簿的工作表.但我遇到的问题是我只能复制并粘贴第一个工作簿的整个工作表.我想知道如何仅选择特定范围(从第5行[第1列到第10列]到第100行[第1列到第10列])并将其粘贴到从第2行第8列开始的第二个工作簿工作表中.

另外我想知道填充列如何从C1到C100以直接的方式表示某些值,而不是像下面那样使用循环

for(i=1;i<2;i++)
{
for(j=1;j<101;i++)
{
worksheet.cells[i,j]="Fixed";
}
}
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止编写的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Excel.Application srcxlApp;
            Excel.Workbook srcworkBook;
            Excel.Worksheet srcworkSheet;
            Excel.Range srcrange;
            Excel.Application destxlApp;
            Excel.Workbook destworkBook;
            Excel.Worksheet destworkSheet;
            Excel.Range destrange;
            string srcPath;
            string destPath;
//Opening of first worksheet and copying
            srcPath="C:\\Documents and Settings\\HARRY\\Desktop\\incident.csv";
            srcxlApp = new Excel.Application();
            srcworkBook = srcxlApp.Workbooks.Open(srcPath);
            srcworkSheet = srcworkBook.Worksheets.get_Item(1);
            srcrange = srcworkSheet.UsedRange;
            srcrange.Copy(Type.Missing);

//opening of the second …
Run Code Online (Sandbox Code Playgroud)

c# excel

10
推荐指数
3
解决办法
4万
查看次数

范围算法和标准算法之间的区别

许多标准库算法在 C++20 中有两个版本:一个在std命名空间中,另一个在std::ranges命名空间中同名。例如,std::ranges::countstd::count都用于计算满足谓词的元素的数量。

为什么这些算法有两个版本?

c++ c++20

9
推荐指数
1
解决办法
229
查看次数

vxworks中的C++ 11

我是VxWorks的新手,我正在VxWorks平台上使用C++开发软件.我想知道VxWorks编译器是否支持C++ 11标准.我问这个问题的原因是因为没有shrink_to_fit()std :: vector函数可用(此函数在c ++ 11标准中引入).所以我想知道有没有办法在VxWorks中用C++ 11标准编译代码.

c++ vxworks

6
推荐指数
1
解决办法
4245
查看次数

使用 emplace 函数插入时 std::unordered_map 给出错误

当我将元素插入到std::unordered_mapusingemplace函数中时,我遇到了这个奇怪的错误,但如果我使用operator[]函数重载则不会。这是我的代码:

#include <iostream>
#include <unordered_map>
#include <memory>

class B {
public:
    B() = default;
    ~B() = default; 
};

class A {
public:
    A() = default;
    ~A() = default;
    
    std::unique_ptr<B> b_ptr;
};

int main() {
    std::unordered_map<std::string, A> mp;
    // mp.emplace("abc", A()); // gives compiler here
    auto& a = mp["def"];
}
Run Code Online (Sandbox Code Playgroud)

编译时我收到巨大的错误打印。这是一个简短的错误注释:template argument deduction/substitution failed

c++

6
推荐指数
2
解决办法
972
查看次数

std::unordered_map insert 仅使迭代器无效,但不会使指向元素节点的引用和指针无效

有人可以解释为什么插入到std::unordered_map容器中只会使迭代器无效,而不会使引用和指针无效。另外,我无法理解 https://en.cppreference.com/w/cpp/container/unordered_map/insert 中的以下声明的含义

如果插入成功,则在元素保存在节点句柄中时获得的指向该元素的指针和引用将失效,而在提取该元素之前获得的指向该元素的指针和引用将变得有效。

c++ unordered-map

6
推荐指数
2
解决办法
614
查看次数

如何使用 RefCell::borrowmut 借用对结构体不同字段的可变引用

如何获取对存储在RefCell. 获得对结构体不同字段的可变引用有什么危害?

use std::cell::{RefCell, RefMut};

#[derive(Default)]
struct A {
    a: i32,
    b: u32,
}

fn main() {
    let mut a_ref_cell: RefCell<A> = Default::default();
    let mut a_obj = a_ref_cell.borrow_mut();
    let a_ref = &mut a_obj.a;
    let b_ref = &mut a_obj.b;
    
    *a_ref = 2;
    *b_ref = 78;
    
    println!("{}, {}", *a_ref, *b_ref);
    println!("Hello, world!");
}
Run Code Online (Sandbox Code Playgroud)

错误

error[E0499]: cannot borrow `a_obj` as mutable more than once at a time
  --> src/lib.rs:62:22
   |
61 |     let a_ref = &mut a_obj.a;
   |                      ----- first mutable …
Run Code Online (Sandbox Code Playgroud)

rust

6
推荐指数
2
解决办法
134
查看次数

使用插入函数将数据插入 std::map 时出现错误:“无法绑定打包字段”

#pragma pack(push,1)有人能告诉我和之间的区别__attribute__((packed))吗?如果我使用第二种类型的结构打包,我会收到编译错误

\n\n
\n
cannot bind packed field \xe2\x80\x98ABC.abc::a\xe2\x80\x99 to \xe2\x80\x98unsigned int&\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n
\n\n

但如果我使用第一种类型的结构打包,则不会出现编译错误。

\n\n

这是我的示例代码:

\n\n
//DataStructure.h\n\n#ifndef DATASTRUCTURE_H_\n#define DATASTRUCTURE_H_\n\nstruct abc\n{\n    unsigned int a;\n    float b;\n}__attribute__((packed));\n\n#endif /* DATASTRUCTURE_H_ */\n\n\n\n//Main.cpp\n#include<iostream>\n#include<map>\n#include "DataStructure.h"\n\n\nint main()\n{\n    struct abc ABC;\n    ABC.a=3;\n    ABC.b=4.6f;\n\n    std::map<unsigned int,struct abc> Mapp;\n    Mapp.insert(std::make_pair(ABC.a,ABC));\n}\n
Run Code Online (Sandbox Code Playgroud)\n

c++ gcc-extensions

5
推荐指数
1
解决办法
3494
查看次数

使用 std::extent 获取数组的第二维

我正在尝试使用 获取二维数组的第二维std::extent,但将输出作为0.

#include <iostream>
#include <type_traits>


int32_t main(int32_t argc, char *argv[]) {
    int32_t arr[10][100];
    
    std::cout << "first dim: " << sizeof(arr) / sizeof(*arr) << std::endl;
    std::cout << "second dim: " << sizeof(*arr) / sizeof(**arr) << std::endl;
    
    std::cout << "rank: " << std::rank<decltype(arr)>{} << std::endl;
    std::cout << "first dim: " << std::extent<decltype(arr)>{} << std::endl;
    std::cout << "second dim: " << std::extent<decltype(*arr)>{} << std::endl;
    
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
2
解决办法
81
查看次数

如何使用循环范围通过引用获取元素来补充 std::vector&lt;bool&gt; 的值

我需要补充 的价值观std::vector<bool>。所以我想到使用 range for 循环通过引用获取元素。但编译器给了我以下错误

error: cannot bind non-const lvalue reference of type 'std::_Bit_reference&' to an rvalue of type 'std::_Bit_iterator::reference'
   13 |     for (auto& bit : rep)
Run Code Online (Sandbox Code Playgroud)

这是我的示例代码

#include <iostream>
#include <vector>

int main() {
    std::vector<bool> rep;
    rep.push_back(true);
    rep.push_back(false);
    rep.push_back(true);
    rep.push_back(false);
    rep.push_back(true);
    rep.push_back(false);

    for (auto& bit : rep)
        bit = !bit;
}
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
1
解决办法
237
查看次数

std::move 对堆栈变量有意义吗

我需要创建一个大小为 1024 的结构列表。所以我试图通过使用移动语义来优化推送操作到列表中。但是移动语义仅对堆分配的内存有意义(据我所知)。有人可以建议我这样做的更好方法。这是我的代码

#include <iostream>
#include <list>
    
struct St {
    int32_t arr[1024];
};
    
int main() {
    std::list<St> struct_list;
    for(int32_t i = 0; i < 1024; ++i) {
        St st; // stack allocated and memory gets deallocated after each loop
        std::cout << &st << std::endl;
        struct_list.emplace_back(std::move(st)); // I feel std::move doesn't make any sense here even if I implement move constructor, still data gets copied into the std::list which is allocated in heap, so not efficient.
        std::cout << &struct_list.back() << "\n" …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

4
推荐指数
1
解决办法
107
查看次数

标签 统计

c++ ×8

c# ×1

c++11 ×1

c++20 ×1

excel ×1

gcc-extensions ×1

rust ×1

unordered-map ×1

vxworks ×1