我正在尝试使用C#.net创建一个excel文档。但是在我能够正确地将一些值写入单元格之后,最后一个单元格具有奇怪的字符,这与我从简单的txt文件中提取的内容无关:
答疑RSIG5oHg7jFnJ9RG8P; k} RI: + J F ]dF Y Pd 1 C OӘ$D0 ..r
这是我的excel创建者类:
class CreateExcelDoc
{
Microsoft.Office.Interop.Excel.Application ExcelUygulama;
Microsoft.Office.Interop.Excel.Workbook ExcelProje;
Microsoft.Office.Interop.Excel.Worksheet ExcelSayfa;
object Missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Range ExcelRange;
string s_dosyaadi = "";
string s_veri = "";
public CreateExcelDoc()
{
ExcelUygulama = new Microsoft.Office.Interop.Excel.Application();
ExcelProje = ExcelUygulama.Workbooks.Add(Missing);
ExcelSayfa = (Microsoft.Office.Interop.Excel.Worksheet)ExcelProje.Worksheets.get_Item(1);
ExcelRange = ExcelSayfa.UsedRange;
ExcelSayfa = (Microsoft.Office.Interop.Excel.Worksheet)ExcelUygulama.ActiveSheet;
ExcelUygulama.Visible = false;
ExcelUygulama.AlertBeforeOverwriting = false;
}
public void HucreyeYaz(int row, int col, string s_veri) // write to a cell
{
if (s_veri != "" && row != 0 && col != 0)
{
Microsoft.Office.Interop.Excel.Range bolge = (Microsoft.Office.Interop.Excel.Range)ExcelSayfa.Cells[row, col];
bolge.Value2 = s_veri;
}
}
public void Kaydet() // saves the excel document
{
ExcelProje.SaveAs(@"C:\excels\dosya.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Missing, Missing, false, Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange);
ExcelProje.Close(true, Missing, Missing);
ExcelUygulama.Quit();
}
}
答案 0 :(得分:0)
您可以通过插入数据并将其另存为xlsx文件来创建html文档,而不是使用Ms Office库。因为,如果您依赖于Ms Office库,则可能必须在运行应用程序的计算机上安装office。
您可以将excel文件另存为html,并可以从应用程序中修改其内容并将其另存为xlsx文件。