如何在MS visual c++中使用excel
How to use excel in MS visual C++
我想做一个windows窗体应用程序。你可以在textBox'es中写入文本,当你按下按钮时,应用程序会创建一个excel文件,并从框中写入文本。我只完成了UI,我知道一些基础知识,但我不知道如何结合MS Visual c++和Excel。
这个答案中列出了很多库:什么是一个简单可靠的C库与Excel文件的工作?
此外,"ExcelFormat Library"是基本的,但听起来它会做你需要的一切。它是免费的,很容易使用。
And Number Duck是我创建的一个商业图书馆
这是一个c#代码取自https://code.google.com/p/excellibrary/,在vc++中使用这段代码并使其工作。:)语法不同,但如果你仔细想想,你会发现它们都是一样的。;)首先,您必须下载ExcelLibrary.dll文件并将其添加到参考项目中。然后加上这两行:使用命名空间ExcelLibrary::CompoundDocumentFormat
使用ExcelLibrary::SpreadSheet;这个项目的目的是提供一个本地。net解决方案来创建、读取和修改
Excel文件,不使用COM互操作或OLEDB连接。
目前实现。xls (BIFF8)格式。将来。xlsx (Excel 2007)也可能是支持。
Example code:
//create new xls file
string file = "C:\newdoc.xls";
Workbook workbook = new Workbook();
Worksheet worksheet = new Worksheet("First Sheet");
worksheet.Cells[0, 1] = new Cell((short)1);
worksheet.Cells[2, 0] = new Cell(9999999);
worksheet.Cells[3, 3] = new Cell((decimal)3.45);
worksheet.Cells[2, 2] = new Cell("Text string");
worksheet.Cells[2, 4] = new Cell("Second string");
worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY-MM-DD");
worksheet.Cells.ColumnWidth[0, 1] = 3000;
workbook.Worksheets.Add(worksheet);
workbook.Save(file);
// open xls file
Workbook book = Workbook.Load(file);
Worksheet sheet = book.Worksheets[0];
// traverse cells
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
{
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
}
// traverse rows by Index
for (int rowIndex = sheet.Cells.FirstRowIndex;
rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
{
Row row = sheet.Cells.GetRow(rowIndex);
for (int colIndex = row.FirstColIndex;
colIndex <= row.LastColIndex; colIndex++)
{
Cell cell = row.GetCell(colIndex);
}
}
相关文章:
- 在传递 com 变体时运行 excel 宏崩溃
- 使用来自 Excel VBA 的 C++ dll 时"Bad DLL calling convention" - 如何解决?
- Excel 不愉快地显示大型 2D 范围公式数组
- 如何从excel文件中读取数据并存储到变量中?
- 错误写入Excel文件-C++
- 如何使用ActiveQt在excel中将工作表附加到工作簿末尾
- 如何更改 Excel DSN 的默认工作簿?
- 随机字符,从强制转换 Arduino 字符串到 Excel BSTR 通过 c++ DLL
- 将带有时区的纪元时间转换为Excel格式的时间?
- 从Excel VBA调用C++DLL只能从Visual Studio中的调试实例工作
- 如何使用 Win32 API 从 Excel VBA 中的非"Single-Threaded Apartment"线程调用 InternetGetProxyInfo
- 如何连接C++和Excel(从C++程序输出到Excel电子表格)
- 我想使用 C++ 从 excel 获取记录,并希望使用特定的列数据(例如书籍 ID)控制输出
- C++使用 adodb 在 64 位 Windows 7 中读取 Excel 文件?
- 使用 XLNT Excel 库时出现问题
- 调试通过 LoadLibrary() 加载到 Excel 中的C++ DLL
- 如何在 VBA/Excel 中创建字符串数组并将其发送到C++ DLL,以便可以在 DLL 中循环访问它
- #VALUE!在 64 位 Excel 中调用 DLL 函数 (C++) 时
- 在C J2ME中读取Excel文件,并从ITQ获取数据
- 从Excel/CSV值创建静态数组