excel数字不能累加_如何修复不累加的Excel编号

excel数字不能累加

If you download bank statement data into Excel, or copy numbers from a website, those numbers might not add up correctly. The bank data might look like numbers, but Excel might see those numbers as text -- not real numbers.

如果将银行对帐单数据下载到Excel中,或从网站复制号码,则这些号码可能无法正确累加。 银行数据可能看起来像数字,但是Excel可能会将这些数字视为文本-而不是实数。

You can fix the numbers manually, as shown in the video below, or use a macro to automate the fix.

您可以手动固定数字,如下面的视频所示,或使用宏自动进行修正。

Fix Numbers That Don’t Add Up http://blog.contextures.com/

数字不累加 (Numbers Don't Add Up)

There are a variety of reasons that numbers don't add up in Excel, and this technique fixes one of the more common problems. If it doesn't work on your data, check out some of the other fixes here.

不能在Excel中累加数字的原因有多种,这种技术解决了较常见的问题之一。 如果对您的数据不起作用,请在此处查看其他一些修复程序

Here is a screen shot of the sample data used in this video – it has cheque numbers and amounts from a fake bank statement. (If your bank only sends you this much information, you should switch to a different bank!)

这是此视频中使用的示例数据的屏幕快照–它具有支票号码和假银行对账单中的金额。 (如果您的银行仅向您发送了这么多信息,则应切换到其他银行!)

numbertext01

观看视频 (Watch the Video)

In the short video below, you will see how to check the cells, and then fix the problem. This is an update for a video that I did in May 2008 – and people are still watching that one on YouTube!

在下面的简短视频中,您将看到如何检查单元格,然后解决问题。 这是我在2008年5月拍摄的一部视频的更新-人们仍然在YouTube上观看该视频!

演示地址

用宏修正数字 (Fix the Numbers with a Macro)

Also, I've updated the macro that automates this fix, to prevent a problem. The old code used the full range that was selected, and that was okay, if you just selected the cells that you wanted to update.

另外,我还更新了自动解决此问题的宏,以防止出现问题。 如果您只是选择了要更新的单元格,那么旧的代码将使用所选的整个范围,这没关系。

However, if you selected an entire column, and then ran the macro, the Used Range was extended to that entire column.

但是,如果选择了整个列,然后运行宏,则“已用范围”将扩展到整个列。

Selection.PasteSpecial Paste:=xlPasteValues, _
     Operation:=xlPasteSpecialOperationAdd

In the revised code, it creates a range from the cells with constants in the selected range, and updates those cells.

在修改后的代码中,它将从单元格中创建一个范围,且常数处于选定范围内,并更新这些单元格。

Set rng = Selection _
  .SpecialCells(xlCellTypeConstants, 23)

That seems to have eliminated the problem. You can get the entire code from my website, or by downloading the sample file.

这似乎消除了问题。 您可以从我的网站获得完整的代码,也可以下载示例文件。

下载样本文件 (Download the Sample File)

To test the manual or macro fix, you can download the sample file from my website. The zipped file is in xlsm format, so enable macros when you open the file.

要测试手动或宏修复程序,您可以从我的网站下载示例文件 。 压缩文件为xlsm格式,因此在打开文件时启用宏。

翻译自: https://contexturesblog.com/archives/2016/01/28/how-to-fix-excel-numbers-that-dont-add-up/

excel数字不能累加

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 如果您想在 Python Excel 数字进行累加,可以使用 openpyxl 库。 以下是一个示例代码,演示了如何打开 Excel 文件,选定一个工作表,读取一列数据,计算它们的总和,并将结果输出到控制台: ```python import openpyxl # 打开 Excel 文件 workbook = openpyxl.load_workbook('example.xlsx') # 选定工作表 worksheet = workbook['Sheet1'] # 读取一列数据 column = worksheet['A'] # 将数据累加 total = sum(cell.value for cell in column if cell.value is not None) # 输出结果 print('Total:', total) ``` 请注意,这将读取所有非空单元格。如果您只需要读取一定范围内的单元格,请使用 `ws.iter_rows()` 或 `ws.iter_cols()` 方法,如下所示: ```python for row in worksheet.iter_rows(min_row=2, max_row=10, min_col=2, max_col=3): for cell in row: print(cell.value) ``` 这将打印从第 2 行到第 10 行、从第 2 列到第 3 列的单元格值。 ### 回答2: 要在Python实现Excel累加功能,可以使用xlrd和xlwt库。首先需要安装这两个库。 累加的过程可以分为以下几个步骤: 1. 打开Excel文件并读取数据。 2. 遍历Excel的单元格,将单元格的数值进行累加。 3. 创建一个新的Excel文件,并将累加结果写入新文件的指定单元格。 下面是一个简单的示例代码: ```python import xlrd import xlwt # 打开Excel文件并读取数据 excel_file = xlrd.open_workbook('data.xlsx') sheet = excel_file.sheet_by_index(0) # 定义累加的初始值 total = 0 # 遍历Excel的单元格并累加值 for row in range(sheet.nrows): for col in range(sheet.ncols): cell_value = sheet.cell_value(row, col) if isinstance(cell_value, float): total += cell_value # 创建新的Excel文件并写入累加结果 new_excel = xlwt.Workbook() new_sheet = new_excel.add_sheet('Result') new_sheet.write(0, 0, '累加结果') new_sheet.write(1, 0, total) new_excel.save('result.xlsx') ``` 以上代码会从名为"data.xlsx"的Excel文件读取数据,并将所有数值单元格的值累加,最后将累加结果写入名为"result.xlsx"的新Excel文件的第一个单元格。 需要注意的是,该代码仅针对简单的Excel表格,如果需要处理更复杂的Excel文件,可能需要根据实际情况进行修改。 ### 回答3: Python可以使用openpyxl库来操作Excel文件,并实现累加的功能。 首先,需要安装openpyxl库。可以使用pip命令来安装,如下所示: ```python pip install openpyxl ``` 接下来,可以使用openpyxl库的load_workbook函数来加载Excel文件,并获得Workbook对象。然后,使用active属性来选择工作表,或者使用get_sheet_by_name函数根据工作表的名称来选择工作表。 在获取到指定的工作表后,可以使用cell函数来获得单元格对象,并通过value属性来访问单元格的值。可以通过遍历单元格的方式进行累加操作。 以下是一个示例代码,实现了对Excel文件A列的数值进行累加的功能: ```python import openpyxl # 加载Excel文件 workbook = openpyxl.load_workbook('test.xlsx') # 选择工作表 worksheet = workbook.active # 设置累加的初始值为0 total = 0 # 遍历A列的单元格 for cell in worksheet['A']: # 获取单元格的值,并进行累加 total += cell.value # 输出累加结果 print('累加结果:', total) ``` 在运行以上代码之前,需要将要处理的Excel文件命名为test.xlsx,并保证该文件与代码文件在同一个目录下。 通过以上的代码,就可以用Python实现对Excel文件指定列的数值进行累加的功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值